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 = '[email protected]'
password = '****************'
hostname = 'outlook.office365.com'
msg = email.mime.text.MIMEText('test')
msg['Subject'] = 'test'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
server = smtplib.SMTP(hostname, 587)
server.ehlo()
server.starttls()
server.ehlo()
server.login(username, password)
server.sendmail(
'[email protected]',
['[email protected]'],
msg.as_string(),
)
server.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment