Last active
June 8, 2017 05:05
-
-
Save Drunkar/7894303 to your computer and use it in GitHub Desktop.
This file contains 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
# coding: utf-8 | |
import smtplib | |
from email.mime.text import MIMEText | |
from email.header import Header | |
from email.utils import formatdate | |
def create_message(from_addr, to_addrs, subject, body): | |
msg = MIMEText(body) | |
msg["Subject"] = subject | |
msg["From"] = from_addr | |
msg["To"] = ",".join(to_addrs) | |
msg["Date"] = formatdate() | |
return msg | |
def send_via_gmail(from_addr, to_addrs, passwd, msg): | |
s = smtplib.SMTP("smtp.gmail.com", 587) | |
s.ehlo() | |
s.starttls() | |
s.ehlo() | |
s.login(from_addr, passwd) | |
s.sendmail(from_addr, to_addrs, msg.as_string()) | |
s.close() | |
def main(): | |
from_addr = "<FROM_ADDR>@gmail.com" | |
passwd = "<PASS>" | |
to_addr = ["<TO_ADDR1>@gmail.com", "<TO_ADDR2>@gmail.com"] | |
title = "title" | |
body = "hongyaaa" | |
msg = create_message(from_addr, to_addrs, title, body) | |
send_via_gmail(from_addr, to_addrs, passwd, msg) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment