2

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.

Jon Cage
  • 33,172
  • 32
  • 120
  • 206

4 Answers4

7

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.

Nicolas Riousset
  • 3,057
  • 1
  • 19
  • 22
1

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.

Jon Cage
  • 33,172
  • 32
  • 120
  • 206
  • I have similar issue some one can help me http://stackoverflow.com/questions/25543233/unable-to-send-the-mailmessage-in-asp-net – Ramesh S Aug 28 '14 at 08:28
0

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.

Community
  • 1
  • 1
Brian Rogers
  • 110,187
  • 27
  • 262
  • 261
  • But apparently not by the client I mentioned in my question. Or is there a chance it might use either of those ports under certain circumstances? – Jon Cage Feb 06 '14 at 15:43
  • I use `System.Net.Mail.SmtpClient` in my production code to send mail via our Microsoft Exchange server on port 587 and it definitely works, SSL and all. I've also used it to send through Gmail (see [here](http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail)). If you can't connect, it could be that your SMTP server does not have that port enabled, or it could be blocked by a firewall somewhere. – Brian Rogers Feb 06 '14 at 15:54
  • Do you explicitly set that port? I'm using the default so perhaps that's the difference? – Jon Cage Feb 06 '14 at 15:58
  • Yes, you need to explicitly set port 587. – Brian Rogers Feb 06 '14 at 15:59
0

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

Gonzalo Gallotti
  • 2,199
  • 1
  • 21
  • 27