python 实现SMTP发送邮件(二)-发送多人邮件
[Python] 纯文本查看 复制代码
|
01
02
03
04
05
06
07
08
09
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
|
import smtplibfrom email.mime.text import MIMETextfrom email.header import Header# 配置邮箱服务器smtpserver = "smtp.163.com"# 用户/密码user = "admin@163.com"password = "123456"# 发送者邮箱sender = "admin@163.com"# 接收者邮箱receiver = ["123456@163.com","234567@qq.com"]# 邮件主题subject = "Python-email2"msg = MIMEText('<html><h1>你好!</h1></html>', "html", "utf-8")msg["Subject"] = Header(subject, "utf-8")# 多人接收邮件,直接显示下面账号的名字msg['From'] = "admin@163.com"msg['To'] = "123456@163.com;[email]234567@qq.com[/email]"if __name__ == '__main__': smtp = smtplib.SMTP() smtp.connect(smtpserver, 25) smtp.login(user, password) smtp.sendmail(sender, receiver, msg.as_string()) smtp.quit() |
需要注意添加上msg[“From”]和msg[“To”],而且要跟接收方邮箱相同(receiver),否则可能会报以下错误:
[Shell] 纯文本查看 复制代码
|
1
|
smtplib.SMTPDataError: (554, b'DT:SPM 163 smtp3,G9xpCgAnchCrbkFdS_YZAA--.189S2 1564569259,please see |
来源:CSDN
作者:码农的世界,你不懂
链接:https://blog.csdn.net/u010395024/article/details/103489315