1. 程式人生 > >python代碼實現發送郵件

python代碼實現發送郵件

*** rec connect tex sendmai lib receiver name nec

#!/usr/bin/env python3
#coding: utf-8
import smtplib
from email.mime.text import MIMEText
from email.header import Header

sender = ‘***‘
receiver = ‘***‘
subject = ‘python email test‘
smtpserver = ‘smtp.163.com‘
username = ‘***‘
password = ‘***‘

msg = MIMEText(‘你好‘,‘text‘,‘utf-8‘)#中文需參數‘utf-8’,單字節字符不需要
msg[‘Subject‘] = Header(subject, ‘utf-8‘)

smtp = smtplib.SMTP()
smtp.connect(‘smtp.163.com‘)
smtp.login(username, password)
smtp.sendmail(sender, receiver, msg.as_string())
smtp.quit()

python代碼實現發送郵件