How can I receive and send email in python? A 'mail server' of sorts.
I am looking into making an app that listens to see if it receives an email addressed to foo@bar.domain.com, and sends an email to the sender.
Now, am I able to do this all in python, would it be best to use 3rd party libraries?
Found a helpful example for reading emails by connecting using IMAP:
Python — imaplib IMAP example with Gmail
Python has an SMTPD module that will be helpful to you for writing a server. You'll probably also want the SMTP module to do the re-send. Both modules are in the standard library at least since version 2.3.
Here is a very simple example:
For more options, error handling, etc, look at the smtplib module documentation.
The sending part has been covered, for the receiving you can use pop or imap
The best way to do this would be to create a windows service in python that receives the emails using imaplib2
Below is a sample python script to do the same.You can install this script to run as a windows service by running the following command on the command line "python THENAMEOFYOURSCRIPTFILE.py install".
Depending on the amount of mail you are sending you might want to look into using a real mail server like postifx or sendmail (*nix systems) Both of those programs have the ability to send a received mail to a program based on the email address.