[LINUX] Debug email sending with Python's smtpd.DebuggingServer

If you are developing a system that sends emails, depending on the network environment you are working on, the limit of Outbound Port 25 Blocking of your provider is 25 Sending emails via port number may be blocked.

You can send it via the SMTP server specified by the provider, but it is troublesome because you have to include the SMTP user information in the development mail sending settings.

At the time of development, I wanted to be able to check the contents of the email sent even if it was not actually sent, so when I was looking for an SMTP server for debugging, I found Python smptd.DebuggingServer. There was a standard library called 2 / library / smtpd.html # debuggingserver-objects).

You can start a dummy SMTP server with the following one-liner.

$ python -m smtpd -n -c DebuggingServer localhost:1025

Looking at the source of the smtpd module, it only implements SMTPServer # process_message, so I think it's a good idea to create a debug server adjusted as necessary.


class DebuggingServer(SMTPServer):
    # Do something with the gathered message
    def process_message(self, peer, mailfrom, rcpttos, data):
        print '---------- MESSAGE FOLLOWS ----------'
        for line in lines:
        print '------------ END MESSAGE ------------'

There was already a library called dsmtpd.

Recommended Posts

Debug email sending with Python's smtpd.DebuggingServer
Easy email sending with haste python3
I tried sending an email with python.
I tried sending an email with SendGrid + Python
Send email with Django
Print debug with PyScribe
Validate E-Mail with Python
Send email with Python
I tried sending an email from Amazon SES with Python
Face recognition with Python's OpenCV
Implement subcommands with Python's argparse
Debug Python with VS Code
Debug with PEPPER python interpreter
Send email using Python's smtplib
Debug shared libraries with VScode
I tried sending an email from the Sakura server with flask-mail