Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
440 views
in Technique[技术] by (71.8m points)

email - Python Gmail BCC and CC


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can try this

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import os

toaddr = ['[email protected]','[email protected]']
cc = ['[email protected]','[email protected]']
bcc = ['[email protected]']

subject = 'Email from Python Code'
fromaddr = '[email protected]'
message = "
  !! Hello... !!"

msg            = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From']    = fromaddr 
msg['To']      = ', '.join(toaddr)
msg['Cc']      = ', '.join(cc)
msg['Bcc'] = ', '.join(bcc)

# Create the body of the message (an HTML version).
text = """Hi  this is the body
"""

# Record the MIME types of both parts - text/plain and text/html.
body = MIMEText(text, 'plain')

# Attach parts into message container.
msg.attach(body)

# Send the message via local SMTP server.
s = smtplib.SMTP('server.com', 587)
s.set_debuglevel(1)
s.ehlo()
s.starttls()
s.login(fromaddr, PASSWORD)
s.sendmail(fromaddr, toaddr, msg.as_string())
s.quit()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...