Guest User

smtp_server

a guest
May 2nd, 2016
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import smtplib
  2. from datetime import datetime
  3. import asyncore
  4. from smtpd import SMTPServer
  5.  
  6. class EmlServer(SMTPServer):
  7.     no = 0
  8.     def process_message(self, peer, mailfrom, rcpttos, data):
  9.         gmail_user = 'lab.performance.reporter@gmail.com'
  10.         gmail_password = 'reporter123'
  11.  
  12.         data = data.replace('\\n', '\n')
  13.  
  14.         print 'Sending email...'
  15.         try:
  16.             server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
  17.             server.ehlo()
  18.             server.login(gmail_user, gmail_password)
  19.             server.sendmail(mailfrom, rcpttos, data)
  20.             server.quit()
  21.             print 'Email sent...'
  22.         except Exception as ex:
  23.             print ex
  24.             print 'Something went wrong...'
  25.  
  26.  
  27. def run():
  28.     foo = EmlServer(('localhost', 5000), None)
  29.     try:
  30.         asyncore.loop()
  31.     except KeyboardInterrupt:
  32.         pass
  33.  
  34.  
  35. if __name__ == '__main__':
  36.     run()
Add Comment
Please, Sign In to add comment