我以前一直用System.Web.Mail发送邮件没出现过什么问题
后来用System.Net.Mail来发送邮件,同样的smtp地址,邮件帐号和密码,就发不出去了。
错误信息如下:
System.Net.Mail.SmtpException: Authentication failed.
有经验的说说大概是啥原因那?!

解决方案 »

  1.   

    我本机用Smtp也不行,后台用CDO来实现的
      

  2.   

    你先要引用程序
    添加引用---在system32中的 cdosys.dll 这个库using CDO;CDO.Message oMsg = new CDO.Message();
    oMsg.From = "发信人地址";
    oMsg.To = "接收人地址";
    oMsg.Subject = "标题";
    oMsg.HTMLBody = "正文内容";
    CDO.IConfiguration iConfg = oMsg.Configuration;
    ADODB.Fields oFields = iConfg.Fields;
    oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = 2;
    oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = to;
    oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = "发信人地址";
    oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value = "发信人帐号";
    oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = "发信人密码";
    oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value = 1;
    oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = 0x0804;
    oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = "邮件服务器"
    oFields.Update();
    oMsg.BodyPart.Charset = "gb2312";
    oMsg.HTMLBodyPart.Charset = "gb2312";
    oMsg.Send();
    oMsg = null;
      

  3.   

    oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = to; 
    "to" 是 "接收人地址"
    oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value = "接收人地址";
      

  4.   

    首先要引用
    using System.Net.Mail
    最好在引用一下
    using System.Text
    using System.IO
    ///添加发件人地址
    MailMessage mailMsg = new MailMessage();
    mailMsg.From = new MailAddress("[email protected]");///添加收件人地址
    mailMsg.To.Add("[email protected]");///添加邮件主题
    mailMsg.Subject = “邮件”;
    mailMsg.SubjectEncoding = Encoding.UTF8;///添加邮件内容
    mailMsg.Body = "ffffff";
    mailMsg.BodyEncoding = Encoding.UTF8;///发送
    public int SenderMail(MailMessage mail)
    {
    ///定义发送邮件的Client
    SmtpClient client = new SmtpClient();
    ///设置邮件服务器主机的IP地址
    client.Host = 
    ///设置邮件服务器的端口
                    client.Port = 
    ///配置发送邮件的属性
    client.DeliveryMethod = SmtpDeliveryMethod.Network;
    client.UseDefaultCredentials = false;
                    ///超时时间
                    client.Timeout = 10000000;
    ///发送邮件
    client.Send(mail);
    return (0);
    }
      

  5.   

    System.Net.Mail.MailMessage oMsg = new System.Net.Mail.MailMessage();
    oMsg.From = new System.Net.Mail.MailAddress("[email protected]"); // 发送邮件的邮件地址
    oMsg.Subject = "ccc"; // 主题
    oMsg.IsBodyHtml = false;                                                    // 是不是HTML邮件
    oMsg.ReplyTo = oMsg.From;                                                   // 回信地址
    oMsg.Priority = System.Net.Mail.MailPriority.Normal;                        // 优先等级
    oMsg.BodyEncoding = Encoding.UTF8;                                          // 邮件编码
    oMsg.To.Add("[email protected]");
    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("xxx.xxx.xxx.xxx");       // 邮件服务器
    smtp.Port = 25;                                                             // 端口号
    smtp.UseDefaultCredentials = false;                                         // 是否使用本地验证
    System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential();
    SMTPUserInfo.UserName = "username";                                         // 用户名
    SMTPUserInfo.Password = "password";                                         // 登录密码
    smtp.Credentials = SMTPUserInfo;                                            // 验证信息
    smtp.EnableSsl = false;           
    smtp.Send(oMsg);
      

  6.   

    6楼的方法可以应用在使用winwebmail的情况下~测试用过,非常地感谢!