简体   繁体   English

将电子邮件发送到来自不同域的多个地址(使用抄送)

[英]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.

相关问题 CC email 和多个 TO email 地址不起作用 - CC email and multiple TO email addresses not working 使用 Outlook SMTP 服务器通过联系表单发送电子邮件但无法发送,因为我需要服务器能够接受多个“发件人”地址 - Using Outlook SMTP server to send email through a contact form but unable to send as I need the server to be able to accept multiple "From" addresses 发送带有python中多个地址附件的电子邮件 - Send an email having an attachment for multiple addresses in python Mandrill API 与收件人(cc)一起发送 email,但它也使用 Django==1.11.10 将邮件作为“TO”发送给收件人(cc) - Mandrill API to send email with recipients(cc), but It also send mail to recipients(cc) as 'TO' using Django==1.11.10 Python SMTP 使用 CC 发送电子邮件 - Python SMTP send email with CC 使用python从Mailgun中提取电子邮件地址 - extract email addresses from Mailgun using python 使用字典提取电子邮件地址。 某些键有多封电子邮件,如何发送到所有电子邮件? - Using a dictionary to pull Email Addresses. Some key's have multiple emails, how do I send to all emails? 为什么电子邮件没有发送到抄送列表? - Why email is not being send to CC list? 使用 Selenium 时无法将多个电子邮件地址添加到 sendkeys() - Unable to add multiple email addresses to sendkeys() while using Selenium 通过一台 SMTP 服务器从多个 email 地址发送电子邮件 - Sending emails from multiple email addresses via one SMTP server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM