Skip to content

Instantly share code, notes, and snippets.

@aewallin
Last active January 22, 2018 09:03
Show Gist options
  • Save aewallin/2a0eb2590c8fe1ad74e5b7ccc2554d03 to your computer and use it in GitHub Desktop.
Save aewallin/2a0eb2590c8fe1ad74e5b7ccc2554d03 to your computer and use it in GitHub Desktop.
# send email, from e.g. cron-jobs and similar
import smtplib
from email.mime.text import MIMEText
def send_email(me, you, smtp_server, subject, text):
msg = MIMEText(text)
msg['Subject'] = subject
msg['From'] = me
msg['To'] = you
s = smtplib.SMTP(smtp_server)
s.sendmail(me, [you], msg.as_string())
s.quit()
if __name__ == "__main__":
text = "The message."
you = "you@work.com"
me = "me@home.com"
smtp_server = "my.smtp.server.com"
subject =" the subject "
send_email(me, you, smtp_server, subject, text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment