【问题标题】:Error While Sending Email Using GmailD使用 Gmail 发送电子邮件时出错
【发布时间】:2012-04-11 14:08:46
【问题描述】:

我在使用 gmailD 发送电子邮件时收到以下错误消息。

SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 Authentication Required。

MailMessage objMailMessage = new MailMessage();
        objMailMessage.From = new MailAddress("suraj.podval@in.vsolutions.com");
        objMailMessage.To.Add(new MailAddress("itslaxman@gmail.com"));
        objMailMessage.Subject = "Test";
        objMailMessage.Body = "Test Test";
        objMailMessage.IsBodyHtml = true;

        SmtpClient smtpClient = new SmtpClient();
        smtpClient.Host = "smtp.gmail.com";
        smtpClient.Port = 587;           
        smtpClient.EnableSsl = true;
        smtpClient.UseDefaultCredentials = false;         
        smtpClient.Credentials = new System.Net.NetworkCredential("user@gmail.com", "password");
        smtpClient.Send(objMailMessage);

【问题讨论】:

  • 您确定您的电子邮件地址和密码设置正确吗?

标签: c# asp.net visual-studio-2010 email


【解决方案1】:

尝试将端口更改为 465

            SmtpMail oMail = new SmtpMail("TryIt");
            SmtpClient oSmtp = new SmtpClient();

            // Your gmail email address
            oMail.From = "gmailid@gmail.com";

            // Set recipient email address
            oMail.To = "support@emailarchitect.net";

            // Set email subject
            oMail.Subject = "test email from gmail account";

            // Set email body
            oMail.TextBody = "this is a test email sent from c# project with gmail.";

            // Gmail SMTP server address
            SmtpServer oServer = new SmtpServer("smtp.gmail.com");

            // If you want to use direct SSL 465 port, 
            // please add this line, otherwise TLS will be used.
            // oServer.Port = 465;

            // detect SSL/TLS automatically
            oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

            // Gmail user authentication
            // For example: your email is "gmailid@gmail.com", then the user should be the same
            oServer.User = "gmailid@gmail.com";
            oServer.Password = "yourpassword";

查看以下链接:http://www.emailarchitect.net/easendmail/kb/csharp.aspx?cat=2

【讨论】:

    猜你喜欢
    • 2014-09-24
    • 1970-01-01
    • 2016-06-03
    • 2017-02-25
    • 1970-01-01
    • 2014-01-04
    • 2015-12-21
    • 2016-07-18
    • 1970-01-01
    相关资源
    最近更新 更多