Wednesday, December 31, 2008

A Simple Python Interface for Gmail

The Problem:
I monitor processes, files, and tasks on my computer. Some monitors are for security others are just to know when a task has finished. Whatever the case, I would like to be notified vie email/text message when something has occurred.

The Solution:
As always... write a script. I wanted something that could easily be used to send an email with or without an attachment. I also wanted to be able to just call a mail function and pass in a recipient, subject, message and attachment.

The Script:
The following script is a pretty simple script that can be imported from another python file. I did not provide command line options because I usually use it in conjunction with another script, so it is always an import. I provide a main part so you can input your username, password, and some email to test the script out. Just run it from the command line to test it.
send_mail.py

Further Explanation:
This could easily extend a general class Mail that would have the same functionality, but you could tailor it to your individual email provider. Contact me if you want such help.

0 comments:

Post a Comment