简体   繁体   中英

Server does not support secure connections

I'm getting the error "Server does not support secure connections" with my code below.

SmtpClient client = new SmtpClient(exchangeServer);
client.UseDefaultCredentials = false;
client.EnableSsl = true;
client.Credentials = new NetworkCredential(user, password);

MailAddress from = new MailAddress(fromAddress);
MailAddress to = new MailAddress(to);
MailMessage mail = new MailMessage(from, to);

// ...

client.Send(mail);

How can I fix this issue?

Your server does not support SSL on the default port; Most won't.

When you set SSL off, you get the message, "The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated"

That tells you that you are not authenticated. Further, you said in a comment, "Because if I set UseDefaultCredentials = true and use my own user address in the "from" address, I am able to send an email successfully."

This is apparently an issue with how the SMTP server is configured. You will need to get appropriate credentials, or have the SMTP server set to allow mail to be sent from the web server.

What port are you using? You may find that you need to specify the port in your SmtpClient object.

client.EnableSsl = false;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM