通过Python脚本给QQ邮箱和163邮箱发送email
- Python 2.7环境
- 邮箱地址和口令需要修改为自己的账号
# -*- coding: UTF-8 -*-
import time
import smtplib
from email.mime.text import MIMEText
from email.header import Header
# 三方 SMTP 服务
mail_host = "smtp.qq.com" # 设置服务器
mail_user = "xxxx@qq.com" # 用户名
mail_pass = "xxxxxxxxxx" # 口令
sender = 'xxxx@qq.com'
receivers = ['xxxx@163.com', 'xxxx@qq.com'] # 收件箱列表
msg = MIMEText('miss can lead to dream, but not vice versa', 'plain', 'utf-8')
msg['From'] = Header("Remote", 'utf-8')
msg['To'] = Header("Here", 'utf-8')
subject = 'Right now - %s' % (time.ctime())
msg['Subject'] = Header(subject, 'utf-8')
try:
s = smtplib.SMTP_SSL(mail_host, 465)
s.login(mail_user, mail_pass)
s.sendmail(sender, receivers, msg.as_string())
print("sent suc")
except smtplib.SMTPException:
print("sent failed")