Created
February 20, 2014 13:43
-
-
Save zed/9113858 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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