The outgoing mail SMTP protocol: how to configure it

The SMTP protocol (Simple Mail Transfer Protocol) is one of the most important protocols in e-mail. All email providers have POP3 / IMAP connection data for incoming email, but they also provide data on the SMTP protocol, the protocol responsible for sending emails from an email client such as Thunderbird or Outlook for Windows. Today in this article we are going to explain the operation of the SMTP protocol for outgoing email (to send emails), and how you can configure it with any email client.

What is the SMTP protocol and what is it for?

The outgoing mail SMTP protocol

The SMTP protocol (Simple Mail Transfer Protocol) or also known as “Simple Mail Transfer Protocol” is the protocol used when we are going to send an email through a mail server. This protocol is used by local email clients to send email messages to the remote mail server, therefore, it acts only in the outbound direction, unlike the POP3 protocol that is used to receive emails, this SMTP is used to send them.

This protocol belongs to the application level of the TCP / IP model, uses the TCP transport layer protocol, and makes use of different ports depending on whether the traffic is encrypted or not:

  • TCP port 25 for unencrypted traffic.
  • TCP port 465 for SSL encrypted traffic (SMTPS).
  • TCP port 587 as an alternate port for SMTPS with TLS.

Currently, the vast majority of email service providers have support for SSL / TLS, in order to encrypt and protect all the data that is sent in email, therefore, we will almost always use ports 465 and 587, depending on how the mail server is configured. For example, in the case of Gmail, TCP port 25 is not allowed to be used because it does not have any type of encryption, however, it supports both port 465 for SSL connections and port 587 for TLS connections.

The SMTP protocol is specifically oriented to sending e-mails, in an “upstream” or outgoing direction, from the local mail client to the mail server, to later send it to its final recipient. Of course, the local email client will store these emails in the sent emails section, regardless of whether we are using Thunderbird or Windows Outlook.

SMTP allows authentication with user / password in clear text from port 25, but currently, few services support this protocol without using any type of encryption, with the aim of providing confidentiality to the authentication and also to the sent email. With the latest versions of SMTPS we can use ports 465 or 587 to have data encryption, authenticity and verification of the integrity of the messages sent.

Operation and exchange of messages

The operation of the SMTP protocol is quite simple, the first thing to keep in mind is that SMTP is a text-based connection-oriented protocol, therefore, it is a reliable protocol when using the TCP transport layer protocol. The mail client communicates with the server through a series of scripts to authenticate, send messages and to close the connection, of course, the mail server will also respond with a series of sequences of commands by way of reply. In the same SMTP session, zero or more transactions can be included, in each of these transactions we will have a total of three scripts / response which are:

  • MAIL: sets the return address.
  • RCPT: establishes a recipient of the message, it can be issued several times depending on the number of recipients.
  • DATA: is the text message of the email, that is, the content of the email itself. It is made up of the header and also the body of the message.

Once we configure the mail client correctly, the email is written directly in the mail client itself, when the “Send” button is clicked, the whole process begins:

  1. The client will establish the connection with the SMTP server waiting for a reply from HELO to receive the server’s identification.
  2. The client starts communication with the MAIL FROM command with the email address, then the server will check that the origin is valid.
  3. The client will send an RCPT TO message incorporating the destination email of the email, depending on the recipients we will have one or more RCPT TO messages. Next, a DATA command is sent to indicate that the body of the message comes line by line.
  4. If the client is not going to send any more emails, it will send a QUIT command to terminate the SMTP session.
  5. In the case of later sending an email, the whole process would start over.

Once we know what SMTP is and how it works, we are going to show you how to easily configure it to send emails through a mail client like Thunderbird or any other.

SMTP Settings

The SMTP protocol can be configured both in email clients to send and receive emails through this client, or directly to use it on servers and to send us email notifications of an event or problem. To configure the SMTP server of our email provider, we generally do not have to do anything, because it is already enabled. However, if you are going to use SMTP in a mail client, you must enable POP3 / IMAP to be able to receive the mail correctly.

Let’s imagine that we want to configure a server or a NAS to send us notifications by email of different events, the only thing we will have to know about the mail server is the following information:

  • Incoming mail server (domain or IP address), in the case of Gmail it is “smtp.gmail.com”
  • Whether or not it requires SSL, in the client we must click on this option. Gmail requires SSL mandatory.
  • Port: 465
  • Username: the full email address, for example: sergio@gmail.com
  • Password: the password that we have put in Gmail.

Once we know all this information that we have available on the official Gmail website, we proceed to fill in the different fields. Next, you can see the SMTP configuration in a pfSense so that it can send us the different events by email. We will have to enable the «Secure SMTP Connection» and choose the correct port.

A very important detail is that if you have two-step authentication, you must activate the “application password” and use this key to access the SMTP, otherwise it will not work for you.

The configuration of the SMTP protocol in any mail client is very simple, because they generally have an internal database with all the predefined data, therefore, we will not have to know them in advance. In the event that you use Thunderbird or Windows Outlook to manage your mail, it is necessary that you activate POP3 or IMAP to receive the mail, unless you only want to send and nothing else.

The first thing we will need is to activate the support of POP3 and / or IMAP by Gmail, by default this function is disabled.

We recommend that you use IMAP because it allows synchronization, POP3 is a fairly old protocol that does not allow many features to manage your mail correctly from multiple clients.

In mail clients like Thunderbird we will only have to put our full name, email account and password, and later choose if we want IMAP or POP3 as incoming mail, the outgoing mail will always be SMTP. Thanks to the internal database, the program will detect the Gmail connection data and we will not have to enter anything. If you look at the following capture, SMTP is being used with SSL / TLS and in the port predefined by Gmail.

Once this is done, we will have to authenticate ourselves in Google to correctly access our email account.

Finally, it will indicate that it has been created correctly, and we can start sending the emails without problems.

The first thing the client will do is receive all the emails in the mailbox, and we can send them via SMTP without any problem.

As you have seen, configuring the SMTP protocol on any computer is really simple, not only in mail clients such as Thunderbird or Outlook, but also in systems such as pfSense, XigmaNAS to receive emails with different notices and alerts, as well as in NAS servers from QNAP and other manufacturers. The only thing that we will have to know is the connection data of the SMTP server of our mail server.