Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7749009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:55:58+00:00 2026-06-01T10:55:58+00:00

I have the following script for sending mails using python import smtplib from email.mime.multipart

  • 0

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 = "myaddr@server.com"
PASSWORD = 'foo'

TOADDR   = ['toaddr1@server.com', 'toaddr2@server.com']
CCADDR   = ['ccaddr1@server.com', 'ccaddr2@server.com']

# 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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:55:59+00:00Added an answer on June 1, 2026 at 10:55 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following script import getopt, sys opts, args = getopt.getopt(sys.argv[1:], h:s) for
I have the following script select c.id from .TBL_COUPONS. as c inner join .TBL_BUSINESS.
I have two separately named checkboxes sending values to the following script. I seem
I am using following script to get Gravatar on my dynamic page, <input type=text
I have to write a script to send mails using unix shell scripts. The
I have the following script in Python. What it does is tries to connect
I have the following code that works: <script type=text/javascript> $(document).ready(function() { // Initialise the
I have the following script. It replaces all instances of @lookFor with @replaceWith in
I have the following script, where the first and third document.writeline are static and
I have the following script which first shows only the first para of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.