1 Python has a module called smtpd, which is used as an SMTP server to implement SMTP functionality for sending emails.
This module has 4 classes:
smtpd.SMTPServer: You need to implement the process_message
function, which allows you to define how to handle the message content and send it to the corresponding mail servers. However, in my experiment on Windows, it didn't actually send emails and only acted as an empty SMTP server.
smtpd.PureProxy
: Acts as a pure proxy for forwarding emails. It can send emails, and the actual data sent to external MX servers can be seen using Wireshark.
smtpd.MailmanProxy
: Acts as a proxy for Mailman.
smtpd.DebuggingServer
: Primarily used for debugging purposes.
2 SMTP is used as a client to send emails, similar to Foxmail and other email clients.
Usually, free SMTP servers require authentication to send emails and do not support relaying.
Therefore, you can only deliver emails to the MX servers of the recipient's email address.
By using nslookup and setting set type=mx
, you can query the MX servers.
These MX servers do not require authentication. The following code can only send emails to email addresses with the qq.com domain. However, there is also a limit on the number of emails that can be sent. If you bypass IP verification through a proxy server, theoretically, you should be able to send unlimited emails.
Code:
import smtpd
import asyncore
print 'proxy start at 25 ...'
server = smtpd.PureProxy(('127.0.0.1', 25), ('mx1.qq.com', 25))
asyncore.loop()