复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37import smtplib from email.mime.text import MIMEText mailto_list = ["123456@qq.com"] # 收件人的邮箱账号 mail_host = "smtp.qq.com" # 设置服务器 mail_user = "123456@qq.com" # 发件人的邮箱 mail_pass = "xxxxxxxxxxx" # 发件人的授权码 mail_postfix = "qq.com" # 发件箱的后缀 def send_mail(to_list, sub, content): # to_list:收件人;sub:主题;content:邮件内容 me = "hello" + "<" + mail_user + "@" + mail_postfix + ">" # 这里的hello可以任意设置,收到信后,将按照设置显示 print(me) msg = MIMEText(content, _subtype='html', _charset='gb2312') # 创建一个实例,这里设置为html格式邮件 msg['Subject'] = sub # 设置主题 msg['From'] = me msg['To'] = ";".join(to_list) try: s = smtplib.SMTP() s.connect(mail_host) # 连接smtp服务器 s.login(mail_user, mail_pass) # 登陆服务器 s.sendmail(me, to_list, msg.as_string()) # 发送邮件 s.close() return True except (Exception): print("失败咯...") return False if __name__ == '__main__': if send_mail(mailto_list, "hello", "<a href='http://www.cnblogs.com/visec479/'>Dana、Li</a>"): print("发送成功") else: print("发送失败") # 链接地址: https://www.cnblogs.com/visec479/p/4142818.html
最后
以上就是隐形小甜瓜最近收集整理的关于使用Python发送HTML格式的邮件的全部内容,更多相关使用Python发送HTML格式内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复