I would like to receive an email with python. Then I want to exit the mailserver and use the content of the email in my script.
For example:
if "any_string" in data:
print "success"
<< exit mailserver >>
<< any other commands >>
Code:
import smtpd
import asyncore
class FakeSMTPServer(smtpd.SMTPServer):
__version__ = 'TEST EMAIL SERVER'
def process_message(self, peer, mailfrom, rcpttos, data):
print 'Receiving message from:', peer
print 'Message addressed from:', mailfrom
print 'Message addressed to :', rcpttos
print 'Message length :', len(data)
print 'Message :', data
return
if __name__ == "__main__":
smtp_server = FakeSMTPServer(('0.0.0.0', 25), None)
try:
asyncore.loop()
except KeyboardInterrupt:
smtp_server.close()