What ports does a 'System.Net.Mail.SmtpClient' need with 'SmtpClient.EnableSsl' set to true?

StackOverflow https://stackoverflow.com/questions/21600563

  •  07-10-2022
  •  | 
  •  

Pergunta

As the title says, what ports does an 'System::Net::Mail::SmtpClient' need with 'SmtpClient::EnableSsl' set to true?

The documentation on the EnableSsl property says the default port for an alternative connection method is 465 but doesn't mention what's used for the connection type it does support.

Edit - If it makes a difference, I'm connecting to Gmail in this instance but generic answers would be welcome.

Foi útil?

Solução 2

A quick test with Wireshark suggested that the answer is port 25 by default

The client uses STARTTLS to re-use an initially unencrypted link to subsequently send encrypted data.

Outras dicas

To send mail to Gmail using System::Net::Mail::SmtpClient and SSL, you must use port 587, as documented in the GMail API.

Both ports 25 and 587 are available on GMail, but Port 587 will require a SMTP authentication before sending a mail, while port 25 won't. Given that port 25 don't require sender authentication, GMail will more agressively filter connections from ip adresses which are not proper mail servers in order to reduce spams.

The GMail API also allows use of port 465, but you can't use it with System::Net::Mail::SmtpClient, as documented by Microsoft. Port 465 is for SMTP over SSL : first establish a SSL connection, then execute the SMTP transaction. With ports 25 and 587, an unencrypted SMTP session is opened first, before switching to SSL using STARTTLS and completing the SMTP transaction. The latter is the method implemented by the .Net SMTP client.

SMTP over SSL is not implemented in SMTPClient .NET Framework.

You must use PORT: 587.

An alternate connection method is where an SSL session is established up front before any protocol commands are sent. This connection method is sometimes called SMTP/SSL, SMTP over SSL, or SMTPS and by default uses port 465. This alternate connection method using SSL is not currently supported.

MSDN SMTPClient doc

In addition to port 25, port 587 is a common port for SMTP clients and works with SSL. You may find this answer useful.

Edit - If you're trying to connect to Gmail, see here and here.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top