New mailer.py

The Python smtplib module offers a high-level interface to what is typically a very low-level process, offering handy dictionary returns and several convenience methods to process and send SMTP e-mail messages.  Anyone who has worked with e-mail knows it can be a beast, with effective diagnosis of issues often involving time-consuming review of cryptic logs and a cascading list of potential “gotchas” to miss or misinterpret; this tool is part one in a suite of utilities that will help to streamline the scripted sending of messages and provide a more human-readable alerts system based on scraping e-mail headers of received messages.

mailer.py

The mailer script itself it very simple.  Because my test host requires SMTP authentication and offers secure connections, I decided to implement a solution using both smtplib.SMTP and smtplib.SMTP_SSL.

SSL sending is detected by the port, and specifying port 465 is (currently) the only way to send using encryption using this utility.  The specification will default to 25 if a host is provided without a port.  Option  -v | --verbose will display the full communication output.

Verbose Example

mailer.py

The SMTPMessage class can be used to directly access this functionality, it expects an argument object with each of the required attributes (like an argparse argument object or a PokeyConfig instance).

Leave a Reply

Your email address will not be published. Required fields are marked *