简体   繁体   中英

Send email to multiple addresses (using cc) from different domains

I've made a little Python script that sends emails using 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.

Obviously those n + m email addresses are from different domains (@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....

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. The addresses in the TO: list correctly receive the email, while only john@mydomain.com , from the CC: list, get the email..

It seems that the CC field works only with same-domain-email ... Any idea?

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()) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM