I have a very hard time to understand how SMTP works.

I've read already:

I know the SMTP server listens on PORT 25 and exchanges commands with the client.

Lets assume I own the domain mydomain.com and have there my own implemented SMTP server running.

Somebody want sent me (for example bob@mydomain.com) an email.

On My server I will see traffic like this:

Server Response: 220 mydomain.com SMTP
Client Sending : HELO domain.com
Server Response: 250 Hello domain.com
Client Sending : MAIL FROM: <me@domain.com>
Server Response: 250 Ok
Client Sending : RCPT TO: <bob@mydomain.com>
Server Response: 250 Ok
Client Sending : DATA
Server Response: 354 End data with <CR><LF>.<CR><LF>
Client Sending : Subject: Example Message
Client Sending : From: me@domain.com
Client Sending : To: bob@mydomain.com
Client Sending :
Client Sending : Yo,
Client Sending :
Client Sending :   Sending a test message.
Client Sending :
Client Sending :   Later,
Client Sending : Carl
Client Sending : .
Server Response: 250 Ok: queued as 45334
Client Sending : QUIT
Server Response: 221 Bye

So my server has now the array of bytes containing the message somewhere in memory.


What I should do now with this message ? (assuming the recipient is on my machine - no relaying is needed)

  • You need a MDA: en.wikipedia.org/wiki/Mail_delivery_agent – Diamant Dec 20 '15 at 11:01
  • 1
    When you ask what you should do now, it sounds like you mean what to do after the client has send the QUIT command. That would actually be too later for anything you wanted to do. After the client has send . and before the server sends 250 Ok: queued as 45334, the server has to store the email. And it must be sure it isn't lost in case of a power failure, so if it was on local disk it has to sync and wait for the disk to confirm that it has been written. – kasperd Dec 20 '15 at 14:25

For the mail to be delivered to the user mailbox, you need a mail delivery agent or MDA.

A mail delivery agent or message delivery agent (MDA) is a computer software component that is responsible for the delivery of e-mail messages to a local recipient's mailbox. Also called an LDA, or local delivery agent. Within the Internet mail architecture, local message delivery is achieved through a process of handling messages from the message transfer agent, and storing mail into the recipient's environment (typically a mailbox).

Read more here: https://en.wikipedia.org/wiki/Mail_delivery_agent

  • I know I need to deliver this messages via an MDA to the maildir, but at the time of asking my question, I have it only as an array of bytes on my server. What is the communication format between SMTP and MDA ? There must be a standard (some RFC ?) because they are interchangeable. – astropanic Dec 20 '15 at 11:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.