[英]Send email to multiple addresses (using cc) from different domains
I've made a little Python script that sends emails using smtplib
. 我制作了一个小小的Python脚本,该脚本使用
smtplib
发送电子邮件。
For example, I have an email that needs to be sent to n users (via To:
field), but I also need to send this email to m other users, via Cc:
field. 例如,我有一封电子邮件需要发送给n个用户(通过“
To:
字段),但是我还需要通过“ Cc:
字段将该电子邮件发送给其他m个用户。
Obviously those n + m email addresses are from different domains (@mydomain, @gmail, @hotmail, @whatever). 显然,这n + m个电子邮件地址来自不同的域(@ mydomain,@ gmail,@ hotmail,@ whatever)。 The emails are correctly delivered to each address if I put the email addresses in the
To:
field, but the same thing doesn't happen if I put the emails in the Cc:
field.... 如果将电子邮件地址放在“
To:
字段中,则电子邮件将正确地传递到每个地址,但是如果将电子邮件地址在“ Cc:
字段中,则不会发生相同的事情。
For example 例如
FROM: me@mydomain.com
TO: alice@mydomain.com, bob@gmail.com, mallory@hotmail.com
CC: john@mydomain.com, robert@yahoo.com, clara@gmail.com
note that the email is sent using a @mydomain.com
account. 请注意,电子邮件是使用
@mydomain.com
帐户发送的。 The addresses in the TO:
list correctly receive the email, while only john@mydomain.com , from the CC:
list, get the email.. “收件人
TO:
列表中的地址可以正确接收电子邮件,而“ CC:
列表中只有john@mydomain.com可以接收电子邮件。
It seems that the CC
field works only with same-domain-email ... Any idea? 似乎
CC
字段仅适用于same-domain-email ...知道吗?
Anyway, this is the code: 无论如何,这是代码:
msg = MIMEText(mailContent)
msg["Subject"] = "This is the subject"
msg["From"] = "me@mydomain.com"
toEmails = ["alice@mydomain.com", "bob@gmail.com", "mallory@hotmail.com"]
ccEmails = ["john@mydomain.com", "robert@yahoo.com", "clara@gmail.com"]
msg["To"] = ",".join(toEmails)
msg["Cc"] = ",".join(ccEmails)
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login("me@mydomain.com", "password")
server.sendmail("me@mydomain.com", toEmails, msg.as_string())
server.quit()
Thanks 谢谢
改变这条线
server.sendmail("me@mydomain.com", toEmails+ccEmails, msg.as_string())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.