Created
October 15, 2018 01:07
-
-
Save MattPitlyk/59fdcf986e25cd25932aa8108ffda400 to your computer and use it in GitHub Desktop.
send email from python
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 characters
def send_mail(msg, to_add, from_add=from_add, | |
smts_server=('smtp.gmail.com', 587), | |
login=(email, password), | |
subj=None, | |
header=True): | |
"""Function to consolidate sending a single email. to_add can be a list.""" | |
if header: | |
msg = "\r\n".join([ | |
"From: " + from_add, | |
"To: " + (', '.join(to_add) if isinstance(to_add, list) else to_add), | |
"Subject: " + str(subj), | |
"", | |
msg | |
]) | |
server = smtplib.SMTP(smts_server[0], smts_server[1]) | |
server.ehlo() | |
server.starttls() | |
server.ehlo() | |
server.login(login[0], login[1]) | |
server.sendmail(from_add, to_add, msg) | |
server.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment