Skip to content

Instantly share code, notes, and snippets.

@zed
Created February 20, 2014 13:43
Show Gist options
  • Select an option

  • Save zed/9113858 to your computer and use it in GitHub Desktop.

Select an option

Save zed/9113858 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Send email using CC header."""
import smtplib
from email.mime.text import MIMEText
from email.header import Header
smtp_host = 'smtp.gmail.com'
login, password = ...
to_emails = [...]
cc_emails = [...]
msg = MIMEText('body…', 'plain', 'utf-8')
msg['Subject'] = Header('subject…', 'utf-8')
msg['From'] = login
msg['To'] = ", ".join(to_emails)
msg['Cc'] = ", ".join(cc_emails)
s = smtplib.SMTP(smtp_host, 587, timeout=10)
s.set_debuglevel(1)
try:
s.starttls()
s.login(login, password)
s.sendmail(msg['From'], to_emails + cc_emails, msg.as_string())
finally:
s.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment