https://www.runoob.com/python3/python3-smtp.html
def sendEmail(message):
# 第三方 SMTP 服务
mail_host = "smtp.qq.com" # 设置服务器
mail_user = "348835027@qq.com" # 用户名
mail_pass = "" # 口令
sender = '348835027@qq.com'
receivers = ['yuhui@163.com'] # 接收邮件,可设置为你的QQ邮箱或者其他邮箱 ,可以设置多个邮箱 ['yuhui@163.com','yuhui1@163.com']
# 邮件内容
message = MIMEText(message, 'plain', 'utf-8')
message['From'] = Header("VB存款利率爬虫", 'utf-8')
message['To'] = Header("VB存款利率爬虫", 'utf-8')
# 主题
subject = '15家银行汇率'
message['Subject'] = Header(subject, 'utf-8')
try:
smtpObj = smtplib.SMTP()
smtpObj.connect(mail_host, 25) # 25 为 SMTP 端口号
smtpObj.login(mail_user, mail_pass)
smtpObj.sendmail(sender, receivers, message.as_string())
print("邮件发送成功")
except smtplib.SMTPException as e:
print("Error: 无法发送邮件", e.args)