Guest User

Untitled

a guest
Jan 19th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import smtplib
  2.  
  3. class Mailer:
  4.     def __init__(self, username, pswd):
  5.         self.username=username
  6.         self.pswd=pswd
  7.  
  8.     def authentication(self):
  9.         server=smtplib.SMTP('smtp.gmail.com',587)      
  10.         server.starttls()
  11.         try:
  12.            server.login(self.username,self.pswd)
  13.            return server
  14.         except smtplib.SMTPAuthenticationError:
  15.            return None
  16.        
  17.     def messagebro(self, server,username,to_address,message):
  18.         server.sendmail(username, to_address, message)
  19.         server.quit()
  20.  
  21.        
  22. def mail(message, to_address):
  23.     username = 'testmailcalicut@gmail.com'
  24.     password="asdasdqwe"
  25.  
  26.     mail_obj = Mailer(username, password)
  27.     server_obj = mail_obj.authentication()
  28.     if server_obj:
  29.         mail_obj.messagebro(server_obj,username, to_address, message)
  30.         return 'sucess'
  31.     else:
  32.         return 'fail'
  33.  
  34. print mail('asdasdfds', 'tshamlikt@gmail.com')
Add Comment
Please, Sign In to add comment