Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import smtplib
- def send_email(recipient, subject, body):
- gmail_user = 'rafal.sikora.pl@gmail.com'
- gmail_password = 'haslo'
- FROM = gmail_user
- TO = recipient if isinstance(recipient, list) else [recipient]
- SUBJECT = subject
- TEXT = body
- # Prepare actual message
- message = """From: %s\nTo: %s\nSubject: %s\n\n%s
- """ % (FROM, ", ".join(TO), SUBJECT, TEXT)
- # SMTP_SSL Example
- server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465)
- server_ssl.ehlo() # optional, called by login()
- server_ssl.login(gmail_user, gmail_password)
- server_ssl.sendmail(FROM, TO, message)
- #server_ssl.quit()
- server_ssl.close()
- print ('successfully sent the mail')
- print ("failed to send mail")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement