分享

python传递变量的html格式,发送html格式信息的邮件,简单测试。

 行走在理想边缘 2023-09-08 发布于四川
a = 100 b = 200 line = """<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>标题</title> </head> <body> <p>%s,%s</p> </body> </html>"""%(a,b) #发送邮件,邮件内容为 读取的捕获异常后写入的数据 def sendmail(smtp_host,smtp_port,subject,smtp_sender,smtp_receive,password): message = MIMEText(line, 'html', 'utf-8') message['Subject'] = subject # 邮件主题显示 message['From'] = smtp_sender # 发件人显示,没有实际作用 message['To'] = smtp_receive # 收件人显示,没有实际作用 # 创建 SMTP 对象 smtp = smtplib.SMTP_SSL(smtp_host, smtp_port) # 连接(connect)指定服务器 smtp.connect(smtp_host, smtp_port) # 登录,需要:登录邮箱和授权码 smtp.login(smtp_sender, password) smtp.sendmail(smtp_sender, "9******8@qq.com", message.as_string()) print('发送成功') smtp.quit() if __name__ == '__main__': smtp_host = "smtp.qq.com" smtp_port = 465 subject = "qq_mail" smtp_sender = "9******8@qq.com" smtp_receive = "2******3@qq.com,9******8@qq.com" password = 'a******e' sendmail(smtp_host,smtp_port,subject,smtp_sender,smtp_receive,password)

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约