SMTP, the Simple Mail Transfer Protocol, is the standard that mail servers use to send and pass email to each other, and that apps use to hand email to a mail server. It is a plain text conversation: the client says who the mail is from and who it is for, sends the message, and the server answers each step with a three-digit code. The current specification is RFC 5321.
How SMTP works
Sending one email takes a short exchange of commands:
- Connect to the server on port 25, 587 or 465.
- EHLO introduces the client and lists the server’s extensions, such as STARTTLS and AUTH.
- STARTTLS and AUTH encrypt the session and log in (for submission ports).
- MAIL FROM gives the envelope sender, also called the Return-Path.
- RCPT TO names each recipient.
- DATA sends the headers and body, ending with a line that holds only a full stop.
- QUIT closes the session.
To deliver to another domain, a server looks up the recipient domain’s MX record and opens an SMTP session with that host.
Example session
S: 220 mx.example.com ESMTP
C: EHLO app.acme.com
S: 250-mx.example.com
S: 250 STARTTLS
C: MAIL FROM:<bounces@send.acme.com>
S: 250 OK
C: RCPT TO:<sam@example.com>
S: 250 OK
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: Acme <hello@acme.com>
C: To: sam@example.com
C: Subject: Your login code
C:
C: Your code is 481203
C: .
S: 250 Queued as 4Kx2
C: QUIT
S: 221 Bye
Reply codes
RFC 5321 groups replies by their first digit:
| Code | Meaning | What to do |
|---|---|---|
| 2xx | Success | Nothing |
| 4xx | Temporary failure | Retry later |
| 5xx | Permanent failure | Do not retry unchanged |
Servers often add an enhanced status code from RFC 3463, such as 5.1.1 (mailbox does not exist). The SMTP error codes guide lists the common ones.
Ports
| Port | Use |
|---|---|
| 25 | Server-to-server relay |
| 587 | Submission with STARTTLS (RFC 6409) |
| 465 | Submission over implicit TLS (RFC 8314) |
Why it matters for app email
Even when you send through an email API, SMTP is what carries the message the last mile to Gmail or Outlook. Bounce reasons come back as SMTP codes, so knowing the difference between a 4xx and a 5xx tells you whether to retry or to stop sending to that address.
Common mistakes
- Connecting on port 25 from a cloud host, where it is often blocked.
- Wrong TLS mode for the port: implicit TLS on 465, STARTTLS on 587.
- Retrying 5xx errors, which hurts your sender reputation.
- Opening a new SMTP connection for every email at volume instead of pooling.
How Mailcandor handles it
Mailcandor accepts SMTP at smtp.mailcandor.com on 465 or 587 through its SMTP relay, alongside the HTTPS API.