Last active
October 22, 2018 14:36
-
-
Save SubhrajitPrusty/6a2b337f11c847a2006c568812ea8461 to your computer and use it in GitHub Desktop.
Send a mail with python
This file contains 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
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