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:
- Sender-client sends e-mail to SMTP server (host A) using SMTP-protocol;
- 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;
- 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;
- 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?