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,Hello Bernhard,
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'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
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 300 |
Nodes: | 16 (2 / 14) |
Uptime: | 69:40:32 |
Calls: | 6,712 |
Files: | 12,244 |
Messages: | 5,356,703 |