有没有用PHP或Go编写的SMTP服务器?

huangapple go评论100阅读模式
英文:

Are there any SMTP servers written in PHP or Go?

问题

我不是指SMTP/IMAP客户端,我是指一个能够接收和发送电子邮件的工作SMTP服务器。

有很多例子是关于部分PHPGo SMTP服务器,它们只监听SMTP连接,难道没有任何示例展示如何发送邮件吗?

我真的很想学习Simple Mail Transfer Protocol的后半部分。我知道有很多不符合标准的糟糕服务器,但我想学习整个协议从开始到结束的实现方式。

英文:

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.

答案1

得分: 16

我认为你对SMTP的工作原理有误解。以下是一个简化版本:

  1. 邮件用户代理(MUA)通过将邮件发送到邮件提交代理(MSA)来将邮件排队等待发送。

  2. MSA通过SMTP连接到邮件传输代理(即“SMTP服务器”)。

  3. 然后,MTA使用DNS查找收件人域的MX记录。然后,它作为SMTP客户端联系收件人的MX服务器。

  4. MX服务器接受邮件信封,然后将其转发给邮件投递代理(MDA)。

  5. MDA将邮件信封放入某个消息存储中,其中一些IMAP或POP3服务器读取邮件。然后,MUA连接到这些服务器以检索邮件。

整个过程使用三个主要命令:MAILRCPTDATA

  • MAIL = 信封信息,退信地址等。
  • RCPT = 收件人。
  • DATA = 邮件正文。

SMTP服务器的响应类似于HTTP,根据错误代码进行响应,基于此,MTA知道如何处理邮件信封(如果是退信,则发送适当的回复等)。

在这个过程中,并没有“检索邮件”这样的概念(暂时忽略ETRN);因为SMTP纯粹用于邮件传输,而不是检索。

英文:

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.

答案2

得分: 3

我发现了一个用PHP编写的完整的SMTP服务器,甚至包括一个恶意的开放中继。

$ sudo php php-smtp.php [ip地址] [端口]
英文:

I found a full SMTP server written in PHP - even includes a nasty open relay.

$ sudo php php-smtp.php [ip-address] [port]

答案3

得分: 1

没有SMTP的“下半部分”,只有协议。如果您的MUA直接通过TCP与邮件服务器交互(而不是使用类似于大多数Unix系统上找到的**/usr/bin/sendmail**二进制文件的辅助程序),那么它使用SMTP协议。MTA在传递邮件时使用相同的协议与其他MTA进行通信。根据情况,它可能使用更多可用的动词集。

查看PHP或Go实现MTA的代码将向您展示一个人/团队如何实现SMTP协议。

英文:

There is no "second half" of SMTP, just the protocol. If your MUA interacts directly over TCP with the mail server (rather than using a helper program like the /usr/bin/sendmail binary found on most Unixes), then it uses the SMTP protocol. The MTA uses the same protocol to talk to other MTAs when delivering the mail. It may use a larger set of the available verbs, depending on the circumstances.

Seeing the code of a PHP or Go implementation of an MTA would show you how one person/team has implemented the SMTP protocol.

答案4

得分: 1

这里有一个仅处理邮件的PHP smtpd服务器 - https://github.com/flashmob/Guerrilla-SMTPd
还有一个Go语言的端口
https://github.com/flashmob/go-guerrilla

英文:

THere's a PHP smtpd server that just processes mail - https://github.com/flashmob/Guerrilla-SMTPd
and a port to go
https://github.com/flashmob/go-guerrilla

答案5

得分: 1

有一个基于ReactPhp编写的非阻塞SMTP服务器:

https://bitbucket.org/david_garcia_garcia/smtpserver

它被设计成允许最终用户自定义身份验证和传递实现,其余的SMTP行为可以直接使用。

英文:

There is a non blocking SMTP server writen in PHP on top of ReactPhp:

https://bitbucket.org/david_garcia_garcia/smtpserver

It is designed for the end user to have custom Authentication and Delivery implementations, the rest of the SMTP behaviour works out of the box.

huangapple
  • 本文由 发表于 2012年9月29日 02:07:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/12645173.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定