How email works

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

How email works

forewordIt just so happened that I moonlight as a teacher in Linux administration. And as homework, I give students a dozen links to various resources, because somewhere there is not enough material, somewhere it is too complicated. And on different resources, the material is often duplicated, and sometimes it starts to diverge. Also, most of the content is in English, but there are students who have difficulty understanding. There are excellent courses from Semaev and Lebedev, and perhaps from others, but, in my opinion, some topics are not sufficiently disclosed, some are not sufficiently connected with others.

Therefore, one day I decided to somehow outline the material and give it to students in a convenient form. But since I'm doing business, why not share it with everyone? At first I tried to make text and dilute it with links, but there are millions of such resources, but what's the point? Somewhere there was a lack of clarity and explanations, somewhere students are too lazy to read the entire text (and not only them) and gaps in knowledge are obtained.

But it's not just the students. Throughout my career, I have worked in IT integrators, and this is a huge experience in working with various systems. As a result, I became a general engineer. Often I have to deal with IT people in various companies and quite often I notice gaps in their knowledge. There are many self-taught people in IT, including me. And I have enough of these gaps, and I would like to help others and myself to get rid of these gaps.

As for me, small videos with information are more interesting and easier to digest, so I decided to try this format. And I know very well that my language is not suspended, it is difficult to listen to me, but I try to become better. For me, this is a new hobby that I want to develop. I used to have a worse microphone, now I mainly solve problems with sound and speech. I want to make quality content and really need objective criticism and advice.

PS Some felt that the video format is not quite suitable and it is better to do it in text. I do not quite agree, but let there be a choice - both video and text.

Video

Next> Mail server operating modes

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

How email works

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

How email works

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

How email works

After the mail client has learned the address of the web server, it accesses it and finds a pre-prepared file with settings for connecting to the mail server in XML format.

How email works

In the case of Thunderbird, the mail client skips the DNS lookup for the autodiscover record and instead attempts to connect to the autoconfig web server directly. and the name of the specified domain. It also tries to find a file with connection settings in XML format on the web server.

How email works

If the mail client does not find a file with the necessary settings, it will try to guess the settings among the frequently used ones. For example, if the domain name is example.com, then the mail server will check if there are servers named imap.example.com and smtp.example.com. If it finds it, it will write 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.

How email works

Then you will notice 2 fields for servers - incoming mail server address and outgoing mail server address. As a rule, in small organizations these addresses are the same, even if they are specified through different DNS names, and in large companies these may be different servers. But it doesn't matter if it's the same server or not - the services behind them are different. One of the most popular mail service bundles 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). From the name, you can guess that Postfix is ​​used to send mail, and Dovecot is used to receive mail by an email client. The mail servers themselves communicate with each other using the SMTP protocol - i.e. Dovecot (MDA) is needed for users.

How email works

Let's say we set up a connection to our mail server. Let's try to send a message. In the message, we indicate our address and the address of the recipient. Now, in order to deliver the message, your email client will send messages to your outgoing mail server.

How email works

When your server receives a message, it will try to figure out who to deliver the message to. Your server can't know the addresses of all mail servers by heart, so it looks up DNS to find a special MX record - pointing to the mail server for that domain. These entries may differ for different subdomains.

How email works

After it knows the address of the recipient's server, it 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 is also looked at by the service responsible for receiving messages by clients (MDA).

How email works

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

But since mail servers operate 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 quite a tasty morsel for attackers, especially spammers. Therefore, modern mail servers have many additional measures to confirm the sender, check for spam, etc. And I will try to cover many of these topics in the following parts.

Source: habr.com

Add a comment