无法在窗口服务器2003上从gmail发送电子邮件

时间:2012-11-10 03:38:42

标签: smtp gmail windows-server-2003

我有一些代码

try {
    SmtpClient SmtpServer = new SmtpClient();
    string sBody = null;
    sBody = "body content";

    var _with1 = SmtpServer;
    _with1.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "abc");
    _with1.Host = "smtp.gmail.com";
    _with1.EnableSsl = true;

    using (MailMessage mail = new MailMessage()) {
         //mail = New MailMessage()
         var _with2 = mail;
         _with2.From = new MailAddress("abc@gmail.com");
         _with2.To.Add("cdf@yahoo.com.vn");
         _with2.Subject = "Thông báo có góp ý cho câu hỏi";
         _with2.Body = sBody;
         _with2.IsBodyHtml = true;
         SmtpServer.Send(mail);
     }
 } catch (Exception) {
     throw;
 }

它在第7窗口正常工作

但是当我在Windows Server 2003上运行它时,它有一个错误: “SMTP服务器需要安全连接或客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。了解详情”

请帮我解决一下!

感谢

1 个答案:

答案 0 :(得分:0)

我找到了原因。我的帐户电子邮件谷歌需要确认IP的服务器,然后它工作正常:)