MailMessage message1 = new MailMessage();
message1.BodyFormat = MailFormat.Html;
message1.Priority = MailPriority.High;
message1.Subject = "Test";
message1.From = "[email protected]";
message1.To = "[email protected]"; 
message1.Body = "welcome";
message1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); 
message1.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","test");
message1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword","test");
SmtpMail.SmtpServer = "smtp.163.com";
SmtpMail.Send(message1); 
错误提示:邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: 邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available Source Error: 
Line 59: message1.Fields.Add(" http://schemas.microsoft.com/cdo/configuration/sendpassword","666666");
Line 60: SmtpMail.SmtpServer = "smtp.163.com";
Line 61: SmtpMail.Send(message1); 
Line 62: }
Line 63: }

解决方案 »

  1.   

    public void SendMail (mailobject mail) 
    { MailMessage mailObj = new MailMessage(); 
    // 设置email的'from'和'to'的地址 
    mailObj.From =mail.MailFrom;
    mailObj.To =mail.MailTo;      
    mailObj.Subject =mail.MailSubject; 
    mailObj.Body =mail.MailBody;  
    System.Web.Mail.MailEncoding enc=new MailEncoding();
    enc=MailEncoding.Base64;  
    MailAttachment att=new MailAttachment(mail.Attachments,enc);
        mailObj.Attachments.Add(att) ; 
    // 使用SmtpMail对象来发送邮件。  
    SmtpMail.SmtpServer=mail.stmpserver; 
    mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate","1");
    mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername",mail.login);
    //密码
    mailObj.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword",mail.pwd);
    SmtpMail.Send(mailObj); 
    }
    public class mailobject
    {
    public string MailFrom;
    public  string MailTo;
    public  string MailSubject;
    public string MailBody;
    public string MailFormat;
    public string mformat;//对邮件进行加密 
    public string  Attachments;//附件 
    public string stmpserver;
    public string login;
    public string pwd;
    public string email_to;}