Back to main menu

Deliverability

What are SMTP commands and what do you need to know about them?

This article will go over what SMTP commands are and how you can get in touch with your SMTP server. Then, we’ll leave you with some essential SMTP commands and response codes.

PUBLISHED ON

PUBLISHED ON

Why do we need SMTP commands and what do they do? Well, we use SMTP (Simple Mail Transfer Protocol) commands to communicate with email servers. These commands are essential for initiating and managing the process of sending emails. By issuing commands like "EHLO" (which initiates the connection), "MAIL FROM" (specifying the sender's email address), and others, we can instruct email servers on how to handle the emails we want to send. Without these commands, the email server wouldn’t know how to process and deliver our messages.

What is SMTP?

Before we get into the specifics of commands, let’s start with the basics. What is SMTP? Simple Mail Transfer Protocol (SMTP) is just a set of rules that handles email sending, receiving, and relaying.

Here’s how it works:

  1. Badge Check

    The SMTP method establishes a connection between your (the sender’s) email client and your SMTP server.

  2. Badge Check

    The SMTP server performs a series of verifications.

  3. Badge Check

    The SMTP server relies on SMTP to ferry your email to your recipient’s inbox provider, like Microsoft Outlook or Gmail.

  4. Badge Check

    Then SMTP severs the connection between your email client and the SMTP server.

To complete the email sending-and-receiving process, your recipient’s email client uses IMAP (another protocol) to download messages from the receiving IMAP email server when your subscriber decides to check their email. IMAP helps manage emails so your recipients can interact with them in their mailbox UI.

Want to know more about SMTP and how it works? If you’re an email geek like us, the answer is yes. Check out our post on what is SMTP and how does it work to learn more.

What is ESMTP?

Hange in there, just one more acronym before we get into commands. ESMTP (Extended Simple Mail Transfer Protocol) extends the capabilities of SMTP to allow sharing of multimedia files, like pictures, audio files, and videos. ESMTP includes additional commands allowing the following functionalities:

  • Badge Check

    Sender authentication

  • Badge Check

    Encrypting emails with SSL

  • Badge Check

    Attaching multimedia files

  • Badge Check

    Restricting email size based on server specifications

  • Badge Check

    Simultaneous transmission to several recipients

Below, we’ll go over both ESMTP and SMTP commands.

Do I even need to know SMTP commands?

Yes: If you’re an email developer, you need to know SMTP commands. But if you’re a regular Gmail account user, you can probably save your brain space for random Game of Thrones trivia.

SMTP commands are used in a particular sequence to facilitate communication between two servers to deliver an email. Here are a few scenarios in which you might want to know SMTP commands:

  • Badge Check

    You want to configure SMTP on your computer or network

  • Badge Check

    You need to troubleshoot your email service

  • Badge Check

    You need to contact your SMTP server

  • Badge Check

    Okay, this one’s pretty specific, but what if you want to access email in the middle of a Telnet session? Telnet allows you to virtually access a computer and implement remote, collaborative two-way access

  • Badge Check

    Also specific: you’re trying to send emails from inside a Linux shell

  • Badge Check

    You want to run an SMTP test

If any of these use cases sound familiar, read on!

How should an SMTP session flow?

Think of an SMTP session as a dialogue between your client and an SMTP server. You send out commands with alphabetical characters, and the server responds with numeric codes.

What’s a client, you ask? Clients can be your email client, like Gmail, which issues commands on your behalf. Or they can be a terminal that you use to issue commands.

Usually, SMTP sessions follow a standard sequence:

  1. Badge Check

    Handshake: The client and the server establish a Transmission Control Protocol (TCP) connection

  2. Badge Check

    Email transfer: The client passes your email message to the SMTP server, and the server performs authentication checks

  3. Badge Check

    Termination: The client and the server close the TCP connection

What are some essential SMTP commands?

Now that we know how an SMTP session looks, let’s go over some essential SMTP and ESMTP commands. We’ve listed these in the sequence in which they might be used:

  1. Badge Check

    The HELO or ELHO command

  2. Badge Check

    The AUTH command

  3. Badge Check

    The MAIL FROM command

  4. Badge Check

    The RCPT TO command

  5. Badge Check

    The DATA command

  6. Badge Check

    The BDAT command

  7. Badge Check

    The VRFY command

  8. Badge Check

    The RSET command

  9. Badge Check

    The QUIT command

  10. Badge Check

    The HELP command

1. The HELO or EHLO command

The first command you’ll need to know is the HELO command. HELO starts the SMTP session and allows the client to greet the server and introduce itself. The command takes the domain name or IP address of the SMTP client as an argument, as shown below.

The HELO command is mostly considered obsolete, but SMTP clients and mechanisms are required to support it as a fallback for conversing with older implementations.

Remember how we said above that ESMTP extended SMTP? As such, ESMTP sometimes has different commands from SMTP. EHLO is the ESMTP alternative to SMTP HELO for servers that support ESMTP. The SMTP server will respond with an SMTP error code if it doesn’t support ESMTP. In this case, you’ll have to start the handshake process all over again. Check out the sample ESMTP command below.

2. The AUTH command

The AUTH command is an ESMTP command that authenticates the SMTP client to the SMTP server. It can take different keywords, depending on the level of security and the login method: PLAIN, LOGIN, and CRAM-MD5. Your session is authenticated when the server provides a positive response. Check out the AUTH command below.

Learn more about AUTH command keywords.

3. The MAIL FROM command

After you’ve initiated the client-server handshake with a HELO or EHLO command, you can use the MAIL FROM command to start a mail transfer. Specifically, you (as the sender) state the sender’s email address in the “from” field. The MAIL FROM command takes the “from” email address as an argument, as shown in the SMTP example code below.

4. The RCPT TO command

Use the RCPT TO command to specify the recipient as an argument. If you have more than one recipient, use RCPT TO to specify each recipient separately. Check out the sample RCPT TO command below.

5. The DATA command

The DATA command is how your SMTP client asks the SMTP server for permission to transfer your email message (the data). Once the server has responded with a 354 code to grant permission, the client delivers your email content line-by-line. Use a final line with a period (“.”) to terminate the data transfer.

Check out the example DATA command below.

6. The BDAT command

The BDAT command is the ESMTP version of the DATA command that transfers email content. BDAT takes two arguments:

  • Badge Check

    The length of the data chunk (in octets)

  • Badge Check

    An indicator that the data chunk is terminating

Check out the sample BDAT command below.

BDAT is used in the Microsoft Exchange Server.

7. The VRFY command

Issue the VRFY command to ask the server to confirm that a particular username or mailbox exists on the localhost. Note that some SMTP email servers ignore the VRFY command since it can be a security loophole that hackers exploit to lift email addresses. Take a look at a sample VRFY command below.

8. The RSET command

Ready to reset your SMTP connection to the initial state without severing your connection? Use the RSET command. This command takes no arguments. Check out the sample command below.

9. The QUIT command

Okay, let’s say you’re finished with your SMTP session. You want to clear the data and terminate your session. Simply use the QUIT command. Once the server responds with a 221 code, your client will close the connection. Check out the sample QUIT command below.

10. The HELP command

This is probably the most useful command. Need help but don’t know where to turn? Try the HELP command first. This command pulls up a list of possible commands that the SMTP server supports. You can supply specific commands as an argument to the HELP command to get help with specific commands. Check out the example HELP command below.

What are the SMTP response codes?

If SMTP commands are how you communicate with an SMTP server via an email client, how does the SMTP server talk to you? That’s easy: through SMTP response codes.

SMTP response codes are three-digit numeric sequences. Each digit tells you something different. Consider a response code of 250:

  • Badge Check

    The first digit (“2”) indicates if your command was good, bad, or incomplete

  • Badge Check

    The second digit (“5”) tells you what kind of response was sent

  • Badge Check

    The third digit (“0”) gives additional information about your command

As you can imagine, the first digit is the most important because it gives you an idea about whether or not your command worked. Check out the following table from RFC 5321 (Simple Mail Transfer Protocol) that lays out what various first digits mean:

Repl­y code­

Mean­ing

Repl­y code­

2.y.z

The comm­and that­ was sent­ was succ­essfully comp­leted on the remo­te serv­er. The remo­te serv­er is read­y for the next­ comm­and.

Mean­ing

3.y.z

The comm­and was acce­pted, but the remo­te serv­er need­s more­ info­rmation befo­re the oper­ation can be comp­leted. The send­ing serv­er need­s to send­ a new comm­and with­ the need­ed info­rmation.

4.y.z

The comm­and wasn­'t acce­pted by the remo­te serv­er for the reas­on that­ migh­t be temp­orary. The send­ing serv­er shou­ld try to conn­ect agai­n late­r to see if the remo­te serv­er can succ­essfully acce­pt the comm­and. The send­ing serv­er will­ cont­inue to retr­y the conn­ection unti­l eith­er a succ­essful conn­ection is comp­leted (ind­icated by a 2.y.­z code­) or fail­s perm­anently (ind­icated by a 5.y.­z code­). An exam­ple of a temp­orary SMTP­ erro­r is low stor­age spac­e on the remo­te serv­er. Once­ more­ spac­e is made­ avai­lable, the remo­te serv­er shou­ld be able­ to succ­essfully acce­pt the comm­and.

5.y.z

The comm­and wasn­'t acce­pted by the remo­te serv­er for the reas­on that­ isn'­t reco­verable. The send­ing serv­er won'­t retr­y the conn­ection and will­ send­ a non-­delivery repo­rt back­ to the user­ who sent­ the mess­age. An exam­ple of an unre­coverable erro­r is a mess­age that­'s sent­ to an emai­l addr­ess that­ does­n't exis­t.

Wrapping up

And that’s it! We know, super light and easy info. Whether you’re looking for an SMTP server solution to power your email sending, or if you’re looking for details on exactly what SMTP port to use (25? 587? 2525?), Mailgun’s got you covered.

As always, don’t hesitate to reach out. Let us help you get sending today.

Learn more about SMTP with Sinch Mailgun

Free SMTP relay service

Particularly for growing businesses, you want access to powerful features, real-time analytics, and the ability to scale as both your email marketing and outgoing mail multiplies. That flexibility is at the core of Mailgun so as your business and marketing campaigns evolve, your free SMTP service doesn’t have to change.

Related readings

How to implement DMARC – A step-by-step guide

Email spoofing is rampant across the internet. Fraudulent emails come in the form of scams, ransomware, and even stock-market manipulation. We see companies lose...

Read More

Seven deliverability strategies to keep you off ISP naughty lists this holiday season

Old Kris Kringle’s not the only one who makes a list and checks it twice. ISPs are notoriously scrupled when it comes to evaluating senders on their way to the inbox. While...

Read More

Gmail expands BIMI support: What it means for email senders

Email authentication and brand protection are key ingredients for a successful email program. Google's latest updates to its BIMI support for Gmail ...

Read More

Popular posts

Email inbox.

Email

5 min

Build Laravel 11 email authentication with Mailgun and Digital Ocean

Read More

Mailgun statistics.

Product

4 min

Sending email using the Mailgun PHP API

Read More

Statistics on deliverability.

Deliverability

5 min

Here’s everything you need to know about DNS blocklists

Read More

See what you can accomplish with the world's best email delivery platform. It's easy to get started.Let's get sending
CTA icon