New guide: how to warm up a dedicated IP without hurting your reputation. Read now →
Log in
MigoSMTP
SMTP and APIUpdated 4 Nov 2026

SMTP commands list: HELO, EHLO, MAIL FROM, RCPT TO, DATA and QUIT explained

A practical reference to the SMTP commands defined in RFC 5321: what HELO, EHLO, MAIL FROM, RCPT TO, DATA, RSET, VRFY, NOOP and QUIT do, the order they run in, and the replies you should expect.

AM
Written by Aarav Mehta
Head of Deliverability
Reviewed by Sana Qureshi
  • Published25 Jul 2024
  • Read time7 min
  • Length1,506 words
Share this guide

SMTP is a plain text conversation. A client opens a connection, sends short commands such as EHLO, MAIL FROM, RCPT TO and DATA, and the server answers each one with a three digit reply code. A normal delivery uses the same handful of commands in the same order: greet, name the sender, name each recipient, send the message, quit.

This reference lists every command you are likely to meet, shows a complete session, and explains the replies and mistakes that cause most real world failures. The authoritative definition is RFC 5321; extensions such as STARTTLS and AUTH are defined in their own RFCs.

Core sequenceEHLO, MAIL FROM, RCPT TO, DATA, then the message, a lone dot, and QUIT
EHLO vs HELOEHLO asks the server to list its extensions; HELO is the original command with no extensions
Reply codes2xx success, 3xx send more, 4xx try later, 5xx permanent failure
Line limitsA command line may be at most 512 octets including the CRLF

The SMTP commands at a glance

CommandPurposeTypical success reply
HELO domainIdentify the client, original form, no extensions250
EHLO domainIdentify the client and request the extension list250 (multi-line)
MAIL FROM:<address>Start a transaction and set the envelope sender250
RCPT TO:<address>Add one envelope recipient; repeat for more250 or 251
DATABegin the message content354, then 250 after the final dot
RSETAbort the current transaction, keep the connection250
VRFYAsk whether a mailbox exists (often disabled)250, 252 or 5xx
EXPNExpand a mailing list (almost always disabled)250 or 5xx
NOOPDo nothing, keep the connection alive250
HELPReturn help text211 or 214
QUITEnd the session221
STARTTLSUpgrade the connection to TLS (RFC 3207)220
AUTH mechanismAuthenticate the client (RFC 4954)235

A complete SMTP session

Lines starting with C: come from the client and S: from the server. The server banner arrives first, before the client says anything.

S: 220 mx.example.org ESMTP ready
C: EHLO client.example.com
S: 250-mx.example.org greets client.example.com
S: 250-SIZE 52428800
S: 250-8BITMIME
S: 250-STARTTLS
S: 250 ENHANCEDSTATUSCODES
C: MAIL FROM:<[email protected]>
S: 250 2.1.0 Sender ok
C: RCPT TO:<[email protected]>
S: 250 2.1.5 Recipient ok
C: DATA
S: 354 End data with <CR><LF>.<CR><LF>
C: From: Bob <[email protected]>
C: To: Alice <[email protected]>
C: Subject: Test
C: Date: Thu, 25 Jul 2024 10:00:00 +0000
C: Message-ID: <[email protected]>
C:
C: Hello Alice.
C: .
S: 250 2.0.0 Queued as 4F2A91
C: QUIT
S: 221 2.0.0 Bye

HELO and EHLO

Every session starts with one of these. The argument should be the fully qualified domain name of the sending host, or an address literal such as [203.0.113.25] when it has no name. Modern clients always try EHLO first. A server that supports extensions answers with a multi-line 250 reply: every line except the last uses 250- and the last uses 250 with a space. Each line after the greeting advertises one extension. A server that does not understand EHLO returns a 5xx and the client falls back to HELO.

The name you send matters for deliverability. Receiving servers compare it with your reverse DNS and may reject or score down names that are not fully qualified or do not resolve. See reverse DNS and the HELO name and HELO and EHLO errors.

MAIL FROM and RCPT TO: the envelope

MAIL FROM opens a mail transaction and gives the envelope sender, also called the return path. Bounces and delivery status notifications go to this address, not to the From: header. A bounce message uses an empty sender, written MAIL FROM:<>, which prevents bounce loops. Extensions add parameters on the same line, for example MAIL FROM:<[email protected]> SIZE=12345 when the server advertised SIZE.

RCPT TO adds one recipient per command. A transaction can carry many recipients, and the server answers each separately, so some can be accepted while others are refused. RFC 5321 requires servers to accept at least 100 recipients per message, although many apply lower limits in practice. Envelope addresses are independent of the To, Cc and Bcc headers, which is how blind copies work. Read more in envelope from and Return-Path versus From.

DATA, dot stuffing and the end of message

After DATA the server replies 354 and from then on treats everything as message content until it sees a line containing only a period, that is CRLF.CRLF. The content is the headers, a blank line and the body, in the format of RFC 5322. The server only gives its real verdict after the final dot: the 250 means it accepted responsibility for delivery, and a 4xx or 5xx at that point means the message was refused after content checks such as spam filtering or DKIM policy.

To stop body text from ending the message early, any body line that begins with a period gets an extra leading period when sent and loses it on receipt. This is called dot stuffing, and libraries do it for you. If you write raw sessions by hand you only need to remember it for lines that start with a dot. Lines in the message must not exceed 998 characters excluding the line ending, which is a limit of the message format, not of the command set.

RSET, NOOP, VRFY, EXPN, HELP and QUIT

  • RSET discards the sender, recipients and any data so far and returns the session to the state after EHLO. Use it to start a new transaction on the same connection after an error.
  • NOOP does nothing except draw a 250. Pools use it to check that a connection is still alive. See SMTP connection pooling.
  • VRFY asks whether an address is valid. Most public servers answer 252 (cannot verify, will accept) or refuse the command because it helps address harvesting. Never depend on it. See VRFY.
  • EXPN asks for the members of a list and is disabled almost everywhere for the same reason.
  • HELP returns free-form help text and is rarely useful.
  • QUIT asks the server to close the connection; it answers 221 and closes. Always send it, rather than dropping the TCP connection, so queued mail is committed cleanly.

Extension commands: STARTTLS and AUTH

The extension list from EHLO tells you which extra commands are allowed. STARTTLS (RFC 3207) switches an existing plain connection to TLS. After a 220 reply both sides negotiate TLS, then the client must send EHLO again because everything learned before the upgrade is discarded. AUTH (RFC 4954) authenticates the client with a mechanism the server advertised, for example AUTH PLAIN. Both are normal on submission port 587, while port 465 uses TLS from the first byte, so there is no STARTTLS command at all. See which port to use and SMTP extensions.

EHLO keywordWhat it enables
STARTTLSUpgrade to TLS on the same connection
AUTH PLAIN LOGINThe authentication mechanisms the server accepts
SIZE nMaximum message size in bytes, and the SIZE= parameter on MAIL FROM
8BITMIMEAllows 8-bit message bodies
PIPELININGLets the client send several commands without waiting for each reply
SMTPUTF8Allows internationalised addresses and headers
ENHANCEDSTATUSCODESAdds codes such as 5.1.1 after the three digit reply
CHUNKINGSends the message with BDAT instead of DATA

Command order and what breaks it

  1. Connect and wait for the 220 banner.
  2. Send EHLO. If advertised and required, run STARTTLS and send EHLO again.
  3. Authenticate with AUTH if the server needs it.
  4. Send MAIL FROM, then one or more RCPT TO.
  5. Send DATA, the message, and the lone dot.
  6. Either start another transaction with MAIL FROM or send QUIT.

Servers enforce this order. Sending RCPT TO before MAIL FROM returns 503 (bad sequence of commands). A transaction cannot start before a successful greeting, and a client that sends nothing for several minutes is typically disconnected with a 421.

Troubleshooting common command errors

ReplyMeaningFix
500 or 502Command not recognised or not implementedCheck spelling; use only commands from the EHLO list
501Syntax error in parameters, often missing angle bracketsWrite MAIL FROM:<[email protected]> exactly
503Commands in the wrong orderFollow the sequence above; use RSET to start clean
530 or 5.7.0Authentication or TLS required firstRun STARTTLS and AUTH before MAIL FROM
550 on RCPT TORecipient rejectedCheck the address; see 550 errors
552Message exceeds size limitCompare with the advertised SIZE value
554 after the dotContent or policy rejectionRead the text of the reply for the reason
421Server is closing the channel, try laterRetry with backoff. See 421 timeouts

Commands are case insensitive, but the local part of an address may be case sensitive on the receiving side, so preserve it exactly as given. To watch these commands live on your own server, see testing an SMTP server from the command line.

When to use this knowledge

You rarely type SMTP commands in production, since libraries send them for you, but the command trace in a log is the clearest evidence of what went wrong. Read the last command and the reply to it, and you usually know whether the problem is the sender, the recipient, the content or the connection. Next, learn the reply codes in SMTP response codes.

Send through a relay that handles the protocol for you Use authenticated SMTP on ports 587 or 465 and keep full delivery logs for every command and reply.

Explore the SMTP relay

References and further reading

Frequently asked questions

What is the difference between HELO and EHLO?

EHLO is the extended greeting that makes the server list its supported extensions such as STARTTLS, AUTH and SIZE. HELO is the original command with no extension negotiation, used only as a fallback.

What does MAIL FROM do in SMTP?

It starts a mail transaction and sets the envelope sender, the address that receives bounces. It is separate from the From header the recipient sees.

How does SMTP know the message has ended?

After DATA, the server treats everything as content until it sees a line with only a period. The server replies 250 once it accepts the message.

Do I have to send QUIT?

You should. QUIT ends the session cleanly with a 221 reply, while dropping the connection can leave the server unsure whether the transaction finished.

Why do I get 503 bad sequence of commands?

You sent a command out of order, for example RCPT TO before MAIL FROM or DATA before any recipient was accepted. Send RSET and repeat the commands in the correct order.

Topics#smtp#protocol#commands#ehlo#rfc 5321
Was this guide helpful?Your answer helps us improve our documentation.

Start sending in minutes.

Create an account, add your domain and send your first email.

Get started Talk to sales