Mailing List Archive

How to add CC and BCC while sending mails using python
Hello all,

Can someone tel me how to add cc's and bcc's while sending mails using
python

Thank you all
Re: How to add CC and BCC while sending mails using python [ In reply to ]
Hi,

* cindy jones [2008-09-30 19:57]:
>
> Can someone tel me how to add cc's and bcc's while sending mails using
> python

Following (tested) snippet should help:

------------------ 8< ------------------------------
from smtplib import SMTP
from email.mime.image import MIMEImage
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

to = 'to_address@example.invalid'
cc = 'cc_address@example.invalid'
bcc = 'bcc_address@example.invalid'

msg = MIMEMultipart()
msg['To'] = to
msg['Cc'] = cc
msg['From'] = 'bernhard@bwalle.de'
msg['Subject'] = 'Test'
text = MIMEText('Das ist ein Test')
text.add_header("Content-Disposition", "inline")
msg.attach(text)

s = SMTP('test.smtp.relay')
s.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
s.quit()
------------------ >8 ------------------------------


Regards,
Bernhard
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to add CC and BCC while sending mails using python [ In reply to ]
On Tuesday, September 30, 2008 8:00:16 AM UTC-8, Bernhard Walle wrote:
> Hi,
>
> * cindy jones [2008-09-30 19:57]:
> >
> > Can someone tel me how to add cc's and bcc's while sending mails using
> > python
>
> Following (tested) snippet should help:
>
> ------------------ 8< ------------------------------
> from smtplib import SMTP
> from email.mime.image import MIMEImage
> from email.mime.text import MIMEText
> from email.mime.multipart import MIMEMultipart
>
> to = 'to_address@example.invalid'
> cc = 'cc_address@example.invalid'
> bcc = 'bcc_address@example.invalid'
>
> msg = MIMEMultipart()
> msg['To'] = to
> msg['Cc'] = cc
> msg['From'] = 'bernhard@bwalle.de'
> msg['Subject'] = 'Test'
> text = MIMEText('Das ist ein Test')
> text.add_header("Content-Disposition", "inline")
> msg.attach(text)
>
> s = SMTP('test.smtp.relay')
> s.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
> s.quit()
> ------------------ >8 ------------------------------
>
>
> Regards,
> Bernhard

Hello Bernhard,

I've tried the above code and the bcc address does not receive the message, on the To & CC addresses receive it.

Here are snippets from my code, perhaps something will stand out to you?

to = 'ed@domain.gov'
cc = 'ed@gmailmail.com'
bcc = 'ed@home.net'

msg = MIMEMultipart()
msg['To'] = to
msg['Cc'] = cc
msg['Subject'] = 'My Subject text here'
msg['From'] = 'edsboss@domain.gov'

smtp = SMTP("smtpserver")
smtp.ehlo()
smtp.sendmail(msg['From'], [to, cc, bcc], msg.as_string())

Thanks in advance..hope you're still out there!!
~Ed
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to add CC and BCC while sending mails using python [ In reply to ]
On Tuesday, September 30, 2008 8:00:16 AM UTC-8, Bernhard Walle wrote:
> Hi,
>
> * cindy jones [2008-09-30 19:57]:
> >
> > Can someone tel me how to add cc's and bcc's while sending mails using
> > python
>
> Following (tested) snippet should help:
>
> ------------------ 8< ------------------------------
> from smtplib import SMTP
> from email.mime.image import MIMEImage
> from email.mime.text import MIMEText
> from email.mime.multipart import MIMEMultipart
>
> to = 'to_address@example.invalid'
> cc = 'cc_address@example.invalid'
> bcc = 'bcc_address@example.invalid'
>
> msg = MIMEMultipart()
> msg['To'] = to
> msg['Cc'] = cc
> msg['From'] = 'bernhard@bwalle.de'
> msg['Subject'] = 'Test'
> text = MIMEText('Das ist ein Test')
> text.add_header("Content-Disposition", "inline")
> msg.attach(text)
>
> s = SMTP('test.smtp.relay')
> s.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
> s.quit()
> ------------------ >8 ------------------------------
>
>
> Regards,
> Bernhard

Hello Bernhard,

I've tried the above code and the bcc address does not receive the message, on the To & CC addresses receive it.

Here are snippets from my code, perhaps something will stand out to you?

to = 'ed@domain.gov'
cc = 'ed@gmailmail.com'
bcc = 'ed@home.net'

msg = MIMEMultipart()
msg['To'] = to
msg['Cc'] = cc
msg['Subject'] = 'My Subject text here'
msg['From'] = 'edsboss@domain.gov'

smtp = SMTP("smtpserver")
smtp.ehlo()
smtp.sendmail(msg['From'], [to, cc, bcc], msg.as_string())

Thanks in advance..hope you're still out there!!
~Ed
--
http://mail.python.org/mailman/listinfo/python-list
Re: How to add CC and BCC while sending mails using python [ In reply to ]
On Friday, November 30, 2012 at 7:00:27?AM UTC+5:30, ake...@gmail.com wrote:
> On Tuesday, September 30, 2008 8:00:16 AM UTC-8, Bernhard Walle wrote:
> > Hi,
> >
> > * cindy jones [2008-09-30 19:57]:
> > >
> > > Can someone tel me how to add cc's and bcc's while sending mails using
> > > python
> >
> > Following (tested) snippet should help:
> >
> > ------------------ 8< ------------------------------
> > from smtplib import SMTP
> > from email.mime.image import MIMEImage
> > from email.mime.text import MIMEText
> > from email.mime.multipart import MIMEMultipart
> >
> > to = 'to_ad...@example.invalid'
> > cc = 'cc_ad...@example.invalid'
> > bcc = 'bcc_a...@example.invalid'
> >
> > msg = MIMEMultipart()
> > msg['To'] = to
> > msg['Cc'] = cc
> > msg['From'] = 'bern...@bwalle.de'
> > msg['Subject'] = 'Test'
> > text = MIMEText('Das ist ein Test')
> > text.add_header("Content-Disposition", "inline")
> > msg.attach(text)
> >
> > s = SMTP('test.smtp.relay')
> > s.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
> > s.quit()
> > ------------------ >8 ------------------------------
> >
> >
> > Regards,
> > Bernhard
> Hello Bernhard,
>
> I've tried the above code and the bcc address does not receive the message, on the To & CC addresses receive it.
>
> Here are snippets from my code, perhaps something will stand out to you?
>
> to = 'e...@domain.gov'
> cc = 'e...@gmailmail.com'
> bcc = 'e...@home.net'
> msg = MIMEMultipart()
> msg['To'] = to
> msg['Cc'] = cc
> msg['Subject'] = 'My Subject text here'
> msg['From'] = 'eds...@domain.gov'
>
> smtp = SMTP("smtpserver")
> smtp.ehlo()
> smtp.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
>
> Thanks in advance..hope you're still out there!!
> ~Ed



I tried this but my mail gets sent only in to but not in cc. Can anyone help?
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to add CC and BCC while sending mails using python [ In reply to ]
sonam Kumari via Python-list schreef op 20/06/2023 om 9:49:
> >
> > I've tried the above code and the bcc address does not receive the message, on the To & CC addresses receive it.
> >
> > Here are snippets from my code, perhaps something will stand out to you?
> >
> > to = 'e...@domain.gov'
> > cc = 'e...@gmailmail.com'
> > bcc = 'e...@home.net'
> > msg = MIMEMultipart()
> > msg['To'] = to
> > msg['Cc'] = cc
> > msg['Subject'] = 'My Subject text here'
> > msg['From'] = 'eds...@domain.gov'
> >
> > smtp = SMTP("smtpserver")
> > smtp.ehlo()
> > smtp.sendmail(msg['From'], [to, cc, bcc], msg.as_string())
> >
> > Thanks in advance..hope you're still out there!!
> > ~Ed
>
>
> I tried this but my mail gets sent only in to but not in cc. Can anyone help?
That looks like it should work. In fact I typed in your code, with some
email addresses of mine and another smtp server, and it does work.
That's to say, I can see in the logs of my smtp server that three mails
are sent out, and I see the mails arriving at the to-address and the
cc-address. The bcc-addres doesn't seem to receive the mail reliably:
sometimes not at all, sometimes in the spam folder. It looks like mail
systems don't like bcc very much. As far as I can see the code is
correct, and there is a good chance the problem is caused by a mail
server not accepting one or more of the messages for some reason.

I added some content to the mail, and that seemed to work better.

So, some suggestions:

- Do you have access to the smtp server to check its logs and see what
is sent, what is not sent, and any possible error messages?
- Try adding some content to the email, something which looks nothing
like spam.

--
"Met een spitsvondig citaat bewijs je niets."
-- Voltaire

--
https://mail.python.org/mailman/listinfo/python-list