Skip to content

Instantly share code, notes, and snippets.

@SubhrajitPrusty
Last active October 22, 2018 14:36
Show Gist options
  • Save SubhrajitPrusty/6a2b337f11c847a2006c568812ea8461 to your computer and use it in GitHub Desktop.
Save SubhrajitPrusty/6a2b337f11c847a2006c568812ea8461 to your computer and use it in GitHub Desktop.
Send a mail with python
import smtplib
import getpass
me = input("Enter sender email : ") # sender email, must enable LessSecureApps
user = me
pwd = getpass.getpass("Enter password for {} : ".format(user))
# you == the recipient's email address
you = input("Enter receiver email : ") # receiver email
msg = {}
msg['Subject'] = 'The contents of Subject'
msg['From'] = me
msg['To'] = you
body = "Hello there!"
msg["body"] = body
# print(msg)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.ehlo()
server.starttls()
server.login(user, pwd)
server.sendmail(me, you, body)
server.close()
print('successfully sent the mail')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment