Created
July 8, 2016 08:12
-
-
Save Shusei-E/d6f96b063161ceb0e4d96956a765ec7e to your computer and use it in GitHub Desktop.
Send BCC e-mail via Gmail by Python
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
import smtplib | |
from email.mime.text import MIMEText | |
from email.header import decode_header | |
from email.header import Header | |
import pandas as pd | |
import random | |
import time | |
# タイトル | |
subject = "[Reminder] Meeting" | |
# 本文 | |
body = """ | |
Dear All, | |
This is a reminder for meeting. | |
日本語もOK。 | |
Sincerely, | |
Meeting organizing committee | |
""" | |
if __name__ == '__main__': | |
username, password = 'xxx@gmail.com', 'xxx' | |
fromAddr = "xxx@gmail.com" | |
host, port = 'smtp.gmail.com', 465 | |
email_default_encoding = 'iso-2022-jp' | |
contact = pd.read_csv("contact_test.csv", encoding="cp932") | |
contact = contact.ix[contact["exclude"]!=1, :] | |
contact = list(contact["E-mail"]) | |
address_list = [contact[i:i+5] for i in range(0,len(contact),5)] | |
for address_part_list in address_list: | |
smtp = smtplib.SMTP_SSL(host, port) | |
smtp.ehlo() | |
smtp.login(username, password) | |
msg = MIMEText(body, 'plain', email_default_encoding) | |
msg['Subject'] = Header(subject, email_default_encoding) | |
msg['From'] = "Meeting Organizer" | |
smtp.sendmail(fromAddr, address_part_list, msg.as_string()) | |
smtp.close() | |
time.sleep(random.uniform(2, 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
contact_test.csv
のE-mail
という欄にメールアドレスが入っている。exlude=1
の人にはメールを送らない。