SMTP ports explained: 25, 465, 587 and 2525

Updated:

Use port 587 or port 465 to send email from an app through an SMTP service. Port 587 starts in plain text and upgrades with STARTTLS. Port 465 starts TLS as soon as the connection opens, which is called implicit TLS, and RFC 8314 (opens in a new tab) prefers it. Port 25 is for server-to-server relay and is blocked by default on AWS EC2 and Google Cloud. Port 2525 is not a standard mail port, but most sending services open it as a fallback for networks that block 587.

Port What the standards say Encryption Use it for
25 SMTP relay between mail servers (RFC 6409 (opens in a new tab)) STARTTLS if both sides offer it Server-to-server transfer. Avoid it from apps and cloud servers
465 “submissions”, message submission over TLS (RFC 8314) Implicit TLS Sending from apps, plugins and mail clients
587 “submission”, message submission (RFC 6409) STARTTLS Sending from apps, plugins and mail clients
2525 Not a mail port in the IANA port registry (opens in a new tab) Usually STARTTLS A fallback when 587 and 465 are blocked

Which SMTP port should I use?

Use port 587 with STARTTLS or port 465 with implicit TLS when your app sends through a service such as SendGrid, Mailgun or Amazon SES. Both are submission ports, and both expect you to log in. Pick 465 if your library supports implicit TLS, since RFC 8314 prefers it. Fall back to 2525 only if your network blocks both, and avoid port 25 from cloud servers.

The port number and the TLS mode have to match. Settings screens often label implicit TLS as “SSL” and STARTTLS as “TLS”, which is why Google tells Workspace users to enter 465 for SSL and 587 for TLS on smtp.gmail.com (opens in a new tab). On port 587, set your client to require STARTTLS rather than use it only when offered, so the login never travels in plain text.

What is the difference between ports 465 and 587?

Port 465 uses implicit TLS: the TLS handshake starts the moment the connection opens. Port 587 uses STARTTLS: the client connects in plain text, sends the STARTTLS command and then switches to TLS. RFC 8314 recommends implicit TLS for submission, but it also says there is no significant security difference between the two when both sides are built correctly and require TLS.

The two ports have different histories:

  • Port 587 is reserved for message submission in RFC 6409, published in November 2011. The RFC says a submission server must, by default, refuse to accept mail from a session that has not logged in. That rule is why port 587 normally asks for a username and password.
  • Port 465 was once registered as “smtps”. RFC 8314 explains that the registration was revoked and the port reassigned, but mail software kept using 465 for submission anyway. RFC 8314, published in January 2018, made it official as the “submissions” port with implicit TLS.

RFC 8314 asks clients and servers to support both STARTTLS on 587 and implicit TLS on 465 during the transition. Most sending services support both. Postmark is one exception: it documents ports 25, 2525 and 587, all with STARTTLS, and no port 465.

Why is port 25 blocked?

Port 25 is the relay port that mail servers use to hand messages to each other, and spam from infected machines has long gone out on it. Cloud providers block it by default. AWS EC2 blocks port 25 traffic to public IP addresses unless you ask for the limit to be removed. Google Cloud blocks port 25 to destinations outside your VPC network and cites the risk of abuse.

What the providers document:

  • AWS EC2. The EC2 service quotas page (opens in a new tab) says that by default EC2 allows outbound port 25 traffic only to private IPv4 addresses, and blocks it to public IPv4 and IPv6 addresses. You can request that the restriction be removed. The Amazon SES SMTP endpoints also accept 587, 2587, 465 and 2465, so an EC2 app can reach SES without port 25.
  • Google Cloud. The Compute Engine guide to sending email (opens in a new tab) says connections to port 25 outside your VPC are blocked, Google Workspace SMTP relay included, though some projects do not have the restriction. Google places no restriction on ports 587 and 465. It suggests a third-party provider such as SendGrid, Mailgun or Mailjet.

The practice is not new. RFC 6409 notes that many sites block outbound traffic on port 25 and send all submissions through submission servers, because of spam sent by malware. Many sending services, including SendGrid, Mailgun, Amazon SES and Resend, still accept connections on 25, but from an app there is no reason to use it.

When should I use port 2525?

Use port 2525 when your host or network blocks 587 and 465. It is not a standard mail port, and the IANA registry assigns 2525 to an unrelated service. Most sending services accept SMTP on it anyway, including SendGrid, Mailgun, SMTP2GO, Postmark, Brevo, Mailjet, Mailtrap and SendPulse. At most of them it behaves like 587, with STARTTLS.

Check the TLS mode your service documents for 2525 before you rely on it:

  • SendGrid runs STARTTLS on 25, 587 and 2525 and recommends 587.
  • Mailgun runs STARTTLS on 25, 587 and 2525, implicit TLS on 465, and recommends 587.
  • SMTP2GO accepts 2525, 8025, 587, 80 and 25 with TLS or without encryption, and SSL on 465, 8465 and 443. That long list helps on networks that block every usual mail port.
  • SendPulse has a setup guide that lists 2525 or 465 for SSL and 587 for TLS.
  • Amazon SES and Resend do not list 2525. They offer 2587 for STARTTLS and 2465 for implicit TLS instead.

Google’s own Compute Engine guide uses 2525 as its example of a custom port to open in a firewall rule.

SMTP ports by service

All ten services below accept port 587, and most also accept 465 and 2525. Postmark leaves out 465, and Amazon SES and Resend use 2587 and 2465 in place of 2525. The table shows which ports each service documents, with the host and login format from each service’s own SMTP page.

Service SMTP host Ports Username Password
Twilio SendGrid smtp.sendgrid.net 25, 587, 2525, 465 The literal word apikey Your SendGrid API key
Mailgun smtp.mailgun.org (US), smtp.eu.mailgun.org (EU) 25, 465, 587, 2525 An SMTP credential login created per sending domain The password set for that SMTP credential
Amazon SES email-smtp.<region>.amazonaws.com, for example email-smtp.us-east-1.amazonaws.com 25, 587, 2587, 465, 2465 SMTP user name created in the SES console (an IAM access key ID) SMTP password generated by SES, derived from the IAM secret access key and different for each Region. It is not the secret access key itself.
Postmark smtp.postmarkapp.com (transactional), smtp-broadcasts.postmarkapp.com (broadcast) 25, 2525, 587 Server API token, or the Access Key of an SMTP token Server API token, or the Secret Key of an SMTP token (shown once)
Resend smtp.resend.com 25, 465, 587, 2465, 2587 the literal word resend your Resend API key
Brevo smtp-relay.brevo.com 587, 2525, 465 Your Brevo account login email An SMTP key generated under Settings, SMTP and API (not an API key)
SMTP2GO mail.smtp2go.com 25, 2525, 8025, 587, 80, 465, 8465, 443 An SMTP User username created under Sending, SMTP Users The password set for that SMTP User
SendPulse SMTP smtp-pulse.com 2525, 465, 587 SMTP login shown in SMTP > Dashboard > Connection using server settings (the PHPMailer guide calls it your SendPulse email login) SMTP password shown in the same place, changeable with Change password
Mailjet in-v3.mailjet.com 25, 80, 465, 587, 588, 2525 Your Mailjet API key (public key) Your Mailjet secret key (private key)
Mailtrap live.smtp.mailtrap.io 587, 465, 2525, 25 The literal word api An API token (each domain has its own tokens, and one is generated when the domain is added)

To compare these services on price and limits, see the best SMTP relay services and the best transactional email services. For WordPress sites, see the best SMTP services for WordPress.

Common port problems and fixes

Most SMTP connection failures come from one of three causes: a blocked port, a TLS mode that does not match the port, or the wrong kind of credential. Each has a quick check. Try the next port before you change anything else, and confirm the username format your service expects.

  • The connection times out on port 25. Your host or network blocks it. Switch to 587 or 465.
  • It times out on 587 as well. Try 465, then 2525 or the alternative ports your service lists.
  • The TLS handshake fails. The mode does not match the port. Use implicit TLS on 465 and STARTTLS on 587 and 2525.
  • Authentication fails. Many services want an API key as the password with a fixed username: the literal word apikey at SendGrid, resend at Resend and api at Mailtrap. Amazon SES uses an SMTP password that SES derives for each Region, which is not your AWS secret access key. See the SendGrid review, the Resend review and the Amazon SES review for the full setup.

Frequently asked questions

Should I use SMTP port 465 or 587?

Either works if your client requires TLS. RFC 8314 prefers implicit TLS on port 465, while port 587 with STARTTLS is the most widely supported, and both SendGrid and Mailgun recommend 587.

Is port 587 secure?

Yes, when your client requires STARTTLS before it logs in. RFC 8314 says STARTTLS on 587 and implicit TLS on 465 have no significant security difference when both sides are built correctly and require TLS.

Why is port 25 blocked on my cloud server?

AWS EC2 blocks port 25 traffic to public IP addresses by default, and Google Cloud blocks port 25 to destinations outside your VPC network, citing the risk of abuse. Connect to your email service on 587 or 465 instead.

What is SMTP port 2525?

It is a non-standard port that many email services, including SendGrid, Mailgun and SMTP2GO, open for SMTP as a fallback. Use it when your network blocks 587 and 465.

What port does Gmail SMTP use?

Google Workspace Help lists port 465 for SSL and port 587 for TLS on smtp.gmail.com. Our Gmail SMTP settings guide covers the login and the sending limits.

Sources

Prices and features come from each vendor's own pages, and other facts from the pages listed here, read on the dates shown. Prices exclude sales tax.