下面爲使用python編寫的發郵件的代碼,注意,代碼中的password不是郵箱的密碼,而是客戶端受權代碼。獲取客戶端受權代碼,以163郵箱爲例:設置-常規設置-客戶端受權密碼。python
from email.mime.text import MIMEText from email.header import Header subject = 'python email test' msg = MIMEText('數據庫中有內容更新,請及時查看', 'plain', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') # 輸入Email地址和口令: from_addr="test1@163.com" password="123456" # 輸入SMTP服務器地址: smtp_server="smtp.163.com" # 輸入收件人地址: to_addr="test2@163.com" import smtplib server = smtplib.SMTP(smtp_server, 25) # SMTP協議默認端口是25 server.set_debuglevel(1) server.login(from_addr, password) server.sendmail(from_addr, [to_addr], msg.as_string()) server.quit()