Skip to content

Instantly share code, notes, and snippets.

@Shusei-E
Created July 8, 2016 08:12
Show Gist options
  • Save Shusei-E/d6f96b063161ceb0e4d96956a765ec7e to your computer and use it in GitHub Desktop.
Save Shusei-E/d6f96b063161ceb0e4d96956a765ec7e to your computer and use it in GitHub Desktop.
Send BCC e-mail via Gmail by Python
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))
@Shusei-E
Copy link
Author

Shusei-E commented Jul 8, 2016

contact_test.csvE-mailという欄にメールアドレスが入っている。exlude=1の人にはメールを送らない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment