Python 發送郵件

分類:IT技術 時間:2017-03-25
from smtplib import SMTP
from email.mime.text import MIMEText
from email.header import Header

def send_email(SMTP_host, from_addr, password, to_addrs, subject, content):
    email_client = SMTP(SMTP_host)
    email_client.login(from_addr, password)
    # create msg
    msg = MIMEText(content,'plain','utf-8')
    msg['Subject'] = Header(subject, 'utf-8')#subject
    msg['From'] = 'main<[email protected]>'
    msg['To'] = "[email protected]"
    email_client.sendmail(from_addr, to_addrs, msg.as_string())

    email_client.quit()

if __name__ == "__main__":
    send_email("smtp.163.com","[email protected]","password","[email protected]","test","hellow")

Tags: password content create import

文章來源:


ads
ads

相關文章
ads

相關文章

ad