Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

后端 未结 25 2451
悲&欢浪女
悲&欢浪女 2020-11-22 02:12

I am using following code to send email. The Code works correctly in my local Machine. But on Production server i am getting the error message

var fromAddres         


        
25条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 03:08

    I have really looked at a lot of ideas, the only solution was this way (works with different email Providers):

                try
            {
                ViewProgressbar("Try to connect mail-server...", progressBar1.Value = 20);
                string host = dsProvider.Rows[y]["POP_hostOut"].ToString();
                int port = int.Parse(dsProvider.Rows[y]["POP_portOut"].ToString());  //587
                string[] email = von1.Split('@');
                string userName = (dsProvider.Rows[y]["login"].ToString() == "email[0]@email[1]")? email[0]+"@"+email[1] : email[0];
                string password = layer.getUserPassword(listSender.SelectedValue.ToString());
                SmtpClient client = new SmtpClient(host, port);
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                //A idea from MSDN but it not works. You got "The server response was: 5.5.1 Authentication Required."
                //System.Net.NetworkCredential myCreds = new System.Net.NetworkCredential(userName, password, host);
                //System.Net.CredentialCache cache = new System.Net.CredentialCache();
                //cache.Add(host, port, "NTLM", myCreds);
                ///cache.GetCredential(host, port, "NTLM");   //NTLM
                client.Credentials = new System.Net.NetworkCredential(userName, password);
                client.Host = host;
                client.Port = port;
                client.EnableSsl = true;
                client.Send(message);
                ViewProgressbar();
            }
            catch (SmtpException ex)...
    

提交回复
热议问题