Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- class Mailer:
- def __init__(self, username, pswd):
- self.username=username
- self.pswd=pswd
- def authentication(self):
- server=smtplib.SMTP('smtp.gmail.com',587)
- server.starttls()
- try:
- server.login(self.username,self.pswd)
- return server
- except smtplib.SMTPAuthenticationError:
- return None
- def messagebro(self, server,username,to_address,message):
- server.sendmail(username, to_address, message)
- server.quit()
- def mail(message, to_address):
- username = 'testmailcalicut@gmail.com'
- password="asdasdqwe"
- mail_obj = Mailer(username, password)
- server_obj = mail_obj.authentication()
- if server_obj:
- mail_obj.messagebro(server_obj,username, to_address, message)
- return 'sucess'
- else:
- return 'fail'
- print mail('asdasdfds', 'tshamlikt@gmail.com')
Add Comment
Please, Sign In to add comment