Skip to content

Instantly share code, notes, and snippets.

@AlonEirew
Last active August 13, 2020 15:22
Show Gist options
  • Save AlonEirew/1ea1435292e0f581db809730451fc9fc to your computer and use it in GitHub Desktop.
Save AlonEirew/1ea1435292e0f581db809730451fc9fc to your computer and use it in GitHub Desktop.
python send mail using smtp
import smtplib
if __name__ == '__main__':
print('Enter email address (eg. yourname@gmail.com):')
gmail_user = input()
print('Enter password OR App password for 2-Step-Verification (https://support.google.com/accounts/answer/185833):')
gmail_password = input()
sent_to = [gmail_user]
subject = "Test"
body = "This is a test report"
msg = "\r\n".join([
"From:" + gmail_user,
"To:" + "; ".join(sent_to),
"Subject:" + subject,
"",
body
])
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(gmail_user, gmail_password)
server.sendmail(gmail_user, sent_to, msg)
server.close()
print("Message sent! :-)")
except Exception as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment