Re: How to add CC and BCC while sending mails using python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bernhard Walle

    Re: How to add CC and BCC while sending mails using python

    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.imag e import MIMEImage
    from email.mime.text import MIMEText
    from email.mime.mult ipart import MIMEMultipart

    to = 'to_address@exa mple.invalid'
    cc = 'cc_address@exa mple.invalid'
    bcc = 'bcc_address@ex ample.invalid'

    msg = MIMEMultipart()
    msg['To'] = to
    msg['Cc'] = cc
    msg['From'] = 'bernhard@bwall e.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
Working...