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()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…