Created
October 3, 2017 13:36
-
-
Save kmonsoor/ec45a604438895c0ca074ca1666bbeb2 to your computer and use it in GitHub Desktop.
Revisions
-
Khaled Monsoor created this gist
Oct 3, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ # src: https://stackoverflow.com/a/12424439/617185 def send_email(user, password, recipient, subject, body): import smtplib FROM = user TO = recipient if type(recipient) is list else [recipient] SUBJECT = subject TEXT = body # Format the email body message = """From: %s\nTo: %s\nSubject: %s\n\n%s """ % (FROM, ", ".join(TO), SUBJECT, TEXT) try: server_ssl = smtplib.SMTP_SSL("smtp.gmail.com", 465) server_ssl.login(FROM, password) server_ssl.sendmail(FROM, TO, message) server_ssl.close() except Exception as e: print("failed to send mail") print(e) else: print 'successfully sent the mail'