How does e-mail go from SMTP to IMAP?

584 views Asked by At

I'm working on programming an IMAP-server, but running into one question: where do the emails come from?

I always thought the basic course of events was this:

  1. Sender-client sends e-mail to SMTP server (host A) using SMTP-protocol;
  2. SMTP server (host A) does a lookup as to where the e-mail is supposed to go, and communicates to SMTP server (host B) using SMTP-protocol;
  3. SMTP-server (host B) then accepts the e-mail, and communicates with the IMAP-server (host B) to magically (?) get the e-mail to that server;
  4. The receiver-client asks the IMAP server (host B) for new e-mails, using the IMAP protocol.

And that made me wonder: how do the e-mails get from the accepting SMTP-server, to the serving IMAP-server? Do they have a protocol for that? Do they just drop it inside a directory?

My own attempt to find an answer...

I have seen usages of the /var/mail directory - with one file per user -, which does not seem like it is intended for a large userbase. Wouldn't it also cause issues when two processes read/write from this at the same time?

I have also seen the Postfix main.cf file possibly contain mailbox_transport = lmtp:unix:/var/imap/socket/lmtp, which looks like the LMTP protocol being used to communicate to the IMAP server using a unix socket. Which would indicate the IMAP-server also "speaking" LMTP?

Are there any other methods being used? Or other protocols?

1

There are 1 answers

0
AnFi On BEST ANSWER

The most common methods of transfer from MTA (SMTP) server and IMAP server:

  1. SMTP and IMAP are server by the same server or servers from the same vendor - any proprietary (secret/undocumented) protocol/method may be used
    [AFAIK it is not common linux/unix solution]

  2. LMTP protocol (slight modification of SMTP) - modern recomendation

  3. MTA executes custom program provided by IMAP server and (typically) feeds message into standard input of the program

  4. MTA puts message into per user Maildir (e.g. ~/.maildir/), IMAP uses the same (shared) maildir

  5. MTA puts incoming messages into standard unix per user mailbox file (/var/mail/username) and IMAP server uses the file as INBOX folder

The tricky part is making MTA reject non existing virtual IMAP users (email account without per email account OS account) in reply to RCPT TO: in SMTP session. MTA must know valid virtual mailboxes.