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
change this line
server.sendmail("me@mydomain.com", toEmails+ccEmails, msg.as_string())