How email works

This is the beginning of a long course about the operation of mail servers. I do not pursue the goal of quickly teaching someone to work with mail servers. There will be a lot of additional information regarding those issues that we will meet along the way, because I try to do the course mainly for those who are just taking their first steps.

image

Foreword
, . , - , - . , . , , , . , , , , , , - , - .

- . , ? , , ? - , - ( ) .

. IT , . . . , . , .

, , . , , , . , . , . .

P.S. , . , — , .

Video



Next> Operating modes of mail servers

To be able to work with e-mail, you need an e-mail client. It can be either a web client, say gmail, owa, roundcube, or an application on a computer - outlook, thunderbird, etc. Suppose you are already registered on some mail service and you need to configure your mail client. You open the program and it asks you for data: name for the account, your email address and password.

image

After you enter this data, your mail client will try to find information about your mail server. This is done to simplify the configuration of the connection to the server, since most users do not know the addresses and connection protocols. To do this, email clients use different methods of finding information about the server and connection settings. These methods may vary depending on the mail client.

image

For example, Outlook uses the “autodiscover” method, the client contacts the dns server and asks for a specific autodiscover entry that is associated with the mail domain that you specified in the settings of your mail client. If the administrator has configured this record on the DNS server, it points to the web server.

image

After the email client finds out the address of the web server, he contacts it and finds a pre-prepared file with the settings for connecting to the mail server in XML format.

image

In the case of Thunderbird, the mail client dispenses with the DNS lookup of the autodiscover DNS record, and immediately tries to connect to the autoconfig web server. and the name of the specified domain. And he also tries to find a connection settings file in XML format on a web server.

image

If the mail client does not find the file with the necessary settings, it will try to guess the settings among the frequently used ones. For example, if the domain is called example.com, then the mail server will check if there are servers with the names imap.example.com and smtp.example.com. If it finds, it will register it in the settings. If the mail client cannot determine the address of the mail server in any way, it will prompt the user to enter the connection data himself.

image

Then you will notice 2 fields for servers - the address of the incoming mail server and the address of the outgoing mail server. As a rule, in small organizations these addresses coincide, even if they are indicated through different DNS names, and in large companies they can be different servers. But it doesn’t matter if it is the same server or not - the services behind them are different. One of the most popular bundles of email services is Postfix & Dovecot. Where Postfix acts as an outgoing mail server (MTA - mail transfer agent), and Dovecot acts as an incoming mail server (MDA - mail delivery agent). The name suggests that Postfix is ​​used to send mail, and Dovecot is used to receive mail by the mail client. The mail servers themselves communicate with each other via the SMTP protocol - i.e. Dovecot (MDA) is needed for users.

image

Suppose we configured a connection to our mail server. Let's try to send a message. In the message we indicate your address and the address of the recipient. Now, to deliver the message, your mail client will send a message to your outgoing mail server.

image

When your server receives a message, it will try to find who to deliver this message to. Your server cannot know the addresses of all mail servers by heart, so it turns to DNS in order to find a special MX record - pointing to the mail server for this domain. These entries may vary for different subdomains.

image

After he learns the recipient’s server address, he sends your message via SMTP to this address, where the recipient’s mail server (MTA) will receive the message and put it in a special directory, which also looks at the service responsible for receiving messages (MDA) by clients.

image

The next time, the recipient's email client asks the incoming mail server for new messages, the MDA will send him your message.

But since mail servers work on the Internet and anyone can connect to them and send messages, as well as mail servers are widely used by various companies to exchange important data, this is a pretty tidbit for attackers, especially for spammers. Therefore, in modern mail servers there are many additional measures for confirming the sender, checking for spam, etc. And I will try to reveal a lot of these topics in the following parts.

All Articles