Skip to content

Instantly share code, notes, and snippets.

@theArjun
Created April 13, 2019 18:49
Show Gist options
  • Select an option

  • Save theArjun/c6068faed16ab29698975507c1e3ec0a to your computer and use it in GitHub Desktop.

Select an option

Save theArjun/c6068faed16ab29698975507c1e3ec0a to your computer and use it in GitHub Desktop.
Send Email from Python using smtplib
RECEIPENT_EMAIL = ''
SENDER_EMAIL = ''
PASSWORD = ''
import smtplib, config
def send_email(subject, msg):
try:
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(config.SENDER_EMAIL, config.PASSWORD)
message = 'Subject: {} {}'.format(subject, msg)
server.sendmail(config.SENDER_EMAIL, config.RECEIPENT_EMAIL, message)
server.quit()
print("Message sent successfully.")
except:
print("Message send failed.")
subject = 'Hello Man'
msg = 'How are you? Been a long time.'
send_email(subject, msg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment