I have the following script for sending mails using python
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import os FROMADDR = "[email protected]" PASSWORD = 'foo' TOADDR = ['[email protected]', '[email protected]'] CCADDR = ['[email protected]', '[email protected]'] # Create message container - the correct MIME type is multipart/alternative. msg = MIMEMultipart('alternative') msg['Subject'] = 'Test' msg['From'] = FROMADDR msg['To'] = ', '.join(TOADDR) msg['Cc'] = ', '.join(CCADDR) # Create the body of the message (an HTML version). text = """Hi this is the body """ # Record the MIME types of both parts - text/plain and text/html. body = MIMEText(text, 'plain') # Attach parts into message container. msg.attach(body) # Send the message via local SMTP server. s = smtplib.SMTP('server.com', 587) s.set_debuglevel(1) s.ehlo() s.starttls() s.login(FROMADDR, PASSWORD) s.sendmail(FROMADDR, TOADDR, msg.as_string()) s.quit()
When I use the script, I see that the mail gets delivered to both toaddr1
and toadd2
However ccaddr1
and ccaddr2
does not receive the mail at all.
Interestingly, when I check the mails received by toaddr1
and toadd2
, it shows that ccaddr1
and ccaddr2
are present in CC.
Is there any error in the script? Initially I thought that this might be an issue with my mail server. I tried it with Gmail and saw the same result. That is, no matter whether its an account in my current mail server or my Gmail account in the CC, the recipient will not receive the mail, even though the people in the 'To' field receive it properly and have the correct addresses mentioned in the CC field
Hit "Compose" to begin a new email, or click on the email thread that you want to reply to and select "Reply" to write a response. 3. If you're typing a new message, the "CC" option will appear to the right of the "To" field. Click "CC" to open up the CC field, and type in the recipient's email address.
The CC abbreviation stands for “carbon copy.” CC recipients receive an exact copy of the email and any further “Reply All” responses in the thread. All recipients of the email will also see who has been CC'd.
Bcc stands for blind carbon copy which is similar to that of Cc except that the Email address of the recipients specified in this field do not appear in the received message header and the recipients in the To or Cc fields will not know that a copy sent to these address.
You can reply to a CC email in exactly the same way as you would a normal email, however, there are few things to remember. If you want to reply only to the original sender then you should click the standard “reply” button. If you want to reply to everyone on the list, then you should click the “reply all” button.
I think that you will need to put the CCADDR with the TOADDR when sending the mail:
s.sendmail(FROMADDR, TOADDR+CCADDR, msg.as_string())
You're correctly adding the addresses to your message, but you will need the cc addresses on the envelope too.
From the docs:
Note The from_addr and to_addrs parameters are used to construct the message envelope used by the transport agents.
You specified the CC entries in the message, but not in the envelope. It's your job to make sure that the message is also sent to the CC and BCC entries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With