Skip to content

Instantly share code, notes, and snippets.

@jdowner
Created January 23, 2015 16:54
Show Gist options
  • Save jdowner/7dfe2572837dba3e3fac to your computer and use it in GitHub Desktop.
Save jdowner/7dfe2572837dba3e3fac to your computer and use it in GitHub Desktop.
How to send email using python
#!/usr/bin/env python
import email.mime.text
import smtplib
username = 'foo@example.com'
password = '****************'
hostname = 'outlook.office365.com'
msg = email.mime.text.MIMEText('test')
msg['Subject'] = 'test'
msg['From'] = 'foo@example.com'
msg['To'] = 'bar@example.com'
server = smtplib.SMTP(hostname, 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(
'foo@example.com',
['bar@example.com'],
msg.as_string(),
)
server.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment