Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

c# - System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated

I'm trying to send email with my website's address from a C# application.
This worked fine for several months until recently. (maybe my provider changes some things or someone else changed settings)

Here's the code:

  private void sendEmail(Email invite) {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(smtpServerName);
            mail.From = new MailAddress(emailUsername);

            mail.To.Add(invite.RecipientEmail);
            mail.Subject = invite.MessageSubject;
            mail.Body = invite.MessageBody;

            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Port = 587;
            SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);
//          SmtpServer.EnableSsl = true;
            SmtpServer.Send(mail);
        }  

Here's the error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required.

Looking at other questions I tried what they suggested, to make SmtpServer.EnableSsl = true. This didn't work at all. It gave the following:

System.Net.Mail.SmtpException: Server does not support secure connections.

I'm guessing I should disable SSL and have it the way it was before.

Any suggestions how to make email sending work again?

EDIT
I've tried without SmtpServer.UseDefaultCredentials = false;
I've tried with it set to true: SmtpServer.UseDefaultCredentials =true;
I've tried commenting that line along with the following //SmtpServer.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That error message is typically caused by one of the following:

  • Incorrect connection settings, such as the wrong port specified for the secured or non-secured connection
  • Incorrect credentials. I would verify the username and password combination, to make sure the credentials are correct.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...