尝试通过gmail SMTP发送邮件时抛出异常

时间:2014-10-15 06:31:43

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

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

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);
        }

1 个答案:

答案 0 :(得分:0)

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

看看:Configure Gmail-Account Outlook