使用python库内的smtplib库
!/usr/bin/python
-- coding: UTF-8 --
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr
my_sender=’1608508177@qq.com’
my_pass = ‘xxxxxxxx’ #由服务器支持的校验码
my_user=’xxxxxxxx@163.com’ #目标邮箱
def mail():
ret=True
try:
msg=MIMEText(‘content’,’plain’,’utf-8’)
msg[‘From’]=formataddr([“FromRunoob”,my_sender])
msg[‘To’]=formataddr([“FK”,my_user])
msg[‘Subject’]=”email test”
server=smtplib.SMTP_SSL("smtp.qq.com", 465) #建立连接
server.login(my_sender, my_pass) # 输入登陆
server.sendmail(my_sender,[my_user,],msg.as_string()) #
server.quit()
except Exception:
ret=False
return ret
ret=mail()
if ret:
print(“succeed”)
else:
print(“failed”)