日期:2014-05-17  浏览次数:20415 次

在asp.net中发送邮件
//命名空间:using System.Net.Mail;
  using System.Net.Mime;

//方法: 
public void SendSMTPEMail(string strSmtpServer, string strFrom, string strFromPass, string strto, string 
 strSubject, string strBody)
  {
  System.Net.Mail.SmtpClient client = new SmtpClient(strSmtpServer);
  client.UseDefaultCredentials = false;
  client.Credentials = new System.Net.NetworkCredential(strFrom, strFromPass);
  client.DeliveryMethod = SmtpDeliveryMethod.Network;

  System.Net.Mail.MailMessage message =
  new MailMessage(strFrom, strto, strSubject, strBody);
  message.BodyEncoding = System.Text.Encoding.UTF8;
  message.IsBodyHtml = true;
  client.Send(message);
  }
调用:SendSMTPEMail("10.3.0.17", "china_cor", "*****","mrchuei@163.com", "测试中。。", msgBody.ToString());

报错提示:指定字符串与电子邮件地址所要求的形式不符

求高手指教,这个问题困扰我很久了,我用matp.163.com的服务器发邮件可以,但是用"10.3.0.17"和账号为"chin_cor"的账号就不行了,这是什么原因了。。。


------解决方案--------------------
http://www.cnblogs.com/hymxtang/archive/2007/06/27/797247.html
------解决方案--------------------
From应该是个电子邮件地址
例如china_cor@google.com
------解决方案--------------------
用邮件服务器ip地址的话,应该还要设置端口了吧,你要知道它把域名映射到了哪个端口上。
NET环境下Email的技术介绍
------解决方案--------------------
指定字符串与电子邮件地址所要求的形式不符

一妹地址不符合要求

C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mail;

namespace MailSender
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            MailMessage objMailMessage;
            MailAttachment objMailAttachment;

            // 创建一个附件对象
            objMailAttachment = new MailAttachment("C:\\1.xml");//发送邮件的附件

            // 创建邮件消息
            objMailMessage = new MailMessage();
            objMailMessage.From = "mytest110@sina.com";//源邮件地址
            objMailMessage.To = "********@qq.com";//目的邮件地址
            objMailMessage.Subject = "邮件发送标题:你好";//发送邮件的标题
            objMailMessage.Body = "邮件发送标内容:测试一下是否发送成功!";//发送邮件的内容
            objMailMessage.Attachments.Add(objMailAttachment);//将附件附加到邮件消息对象中

            //接着利用sina的SMTP来发送邮件,需要使用Microsoft .NET Framework SDK v1.1和它以上的版本
            //基本权限
            objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");

            //用户名
            objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "mytest110");

            //密码
            objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "******");

            //如果没有上述三行代码,则出现如下错误提示:服务器拒绝了一个或多个收件人地址。服务器响应为:530 Authentication required

            //SMTP地址
            SmtpMail.SmtpServer = "smtp.sina.com";

            // 开始发送邮件
            // 在发送之前,去新浪邮箱里开启POP/SMTP设置    邮箱设置->账户->POP/SMTP设置->开启
            // 否则会报错误0x80040217. The server response was not available
            SmtpMail.Send(objMailMessage);
        }
    }
}

------解决方案--------------------
C# code

/// <summary>
    /// 邮件发送
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>