【问题标题】:Exception thrown while trying to send mail through gmail SMTP尝试通过 gmail SMTP 发送邮件时引发异常
【发布时间】:2014-10-15 06:31:43
【问题描述】:

尝试通过以下代码发送邮件时引发以下异常:

SMPT server requires a secure connection or the client was not authenticated. The server response was 5.5.1. Authentication required

C#

string E_mail_ID = "hidden";
        try
        {
            SmtpClient gmail_client = new SmtpClient("smtp.gmail.com");
            gmail_client.Port = 587;

            gmail_client.EnableSsl = true;
            gmail_client.Timeout = 100000;
            gmail_client.DeliveryMethod = SmtpDeliveryMethod.Network;
            gmail_client.UseDefaultCredentials = false;
            gmail_client.Credentials = new NetworkCredential("hidden", "hidden");

            MailMessage msg = new MailMessage();
            msg.From = new MailAddress("hidden");
            msg.To.Add(E_mail_ID.Trim());              
            msg.Body = "Request for quotation from Jeet fly ash products, a unit of Vidya shakti niyas";
            msg.Attachments.Add(new Att![enter image description here][1]achment(pdfFile));
            gmail_client.Send(msg);
            MessageBox.Show("RFQ sent to vendor successfully");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }

【问题讨论】:

  • 异常在哪里?
  • 还有什么例外?
  • “SMPT 服务器需要安全连接或客户端未通过身份验证。服务器响应为 5.5.1。需要身份验证”。这是我发送到邮件地址时消息框显示的异常

标签: c# .net system.net.mail system.net


【解决方案1】:

尝试端口:465 - 这是 gmail 的 ssl。

看一看:Configure Gmail-Account Outlook

【讨论】:

  • 同样的异常即将到来。
  • 嗯.. 你在使用 Google-Authenticator 吗? & 您的帐户是否启用了 POP?
  • @Jagmeet:taka 看看这个线程 - 使用 System.Net.Mail 而不是 System.Web.Mail(因为 web.mail 存在 ssl 问题)stackoverflow.com/questions/32260/…
猜你喜欢
  • 2014-05-16
  • 1970-01-01
  • 2021-05-08
  • 2014-08-27
  • 2018-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-13
相关资源
最近更新 更多