Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any SMTP servers written in PHP or Go?

Tags:

php

email

go

smtp

I don't mean SMTP/IMAP clients, I mean a working SMTP server that can both receive and send email.

There are lots of examples of partial PHP and Go SMTP servers that only listen for SMTP connections - aren't there any which show how to send mail?

I'm really interested in learning this second half of the Simple Mail Transfer Protocol. I understand that there are a lot of bad servers which vary from the standard - but I want to learn how the whole protocol from start to finish is implemented.

like image 239
Xeoncross Avatar asked Sep 28 '12 18:09

Xeoncross


1 Answers

I think you misunderstand how SMTP is supposed to work. Here is a simplified version:

  1. The Mail User Agent (MUA) queues a message for delivery by sending it to the Mail Submission Agent (MSA).

  2. MSA connects to the Mail Transfer Agent (the "smtp server") over SMTP.

  3. The MTA then uses DNS to lookup the MX record for the recipient's domain. It then contacts the recipient's MX server as a SMTP client.

  4. The MX server accepts the envelope; it then forwards it to a Mail Delivery Agent (MDA).

  5. MDA then puts the envelope in some message store where some IMAP or POP3 server reads messages. The MUA then connects to these servers to retrieve the message.

The entire process uses three main commands. MAIL, RCPT and DATA.

  • MAIL = Envelope information, bounce addresses, etc.
  • RCTP = The recipient.
  • DATA = The payload.

The SMTP server responds - much like HTTP actually, with error codes and based on that, the MTA knows what to do with the envelope (its a bounce back, so send appropriate reply, etc.)

In this process there is no such thing as "retrieve email" (ignoring ETRN for a bit); as SMTP is purely for email transmission and not retrieval.

like image 193
Burhan Khalid Avatar answered Oct 19 '22 23:10

Burhan Khalid