0

I am using the following code to send a file to 3 recipients including me.

    import smtplib
    from email.MIMEMultipart import MIMEMultipart
    from email.MIMEBase import MIMEBase
    from email import Encoders


    SUBJECT = "Successful !"

    msg = MIMEMultipart()
    msg['Subject'] = SUBJECT
    msg['From'] = <myemail>

    emails=["<myemail>","<email2>","<email3>"]
    msg['To'] = ', '.join(emails)

    part = MIMEBase('application', "octet-stream")
    part.set_payload(open("test.txt", "rb").read())
    Encoders.encode_base64(part)

    part.add_header('Content-Disposition', 'attachment; filename="success.txt"')

    msg.attach(part)
    server = smtplib.SMTP("<server_address>")
    server.sendmail(msg['From'],msg['To'], msg.as_string())

In this case, I receive the email but not the other two recipients.

I also tried using

     server.sendmail(msg['From'],emails, msg.as_string())

in place of the last line. Again, I receive the email, but not the other two recipient.

Adam Wagner
  • 15,469
  • 7
  • 52
  • 66
nsh
  • 1,499
  • 6
  • 13
  • 14
  • Actually both these way work successfully !! I was not sure if my other recipients are receiving the mails...They are sucesssfully receiving emails from me... – nsh Aug 30 '11 at 00:05
  • I used this link to get the solution for my problem: http://stackoverflow.com/questions/3362600/how-to-send-email-attachments-with-python – nsh Aug 30 '11 at 00:14

1 Answers1

0

Re-posting answer from author of question.

Actually both these way work successfully !! I was not sure if my other recipients are receiving the mails...They are sucesssfully receiving emails from me... – nsh Aug 30 '11 at 0:05

I used this link to get the solution for my problem: stackoverflow.com/questions/3362600/… – nsh Aug 30 '11 at 0:14

Lars Nordin
  • 2,785
  • 1
  • 22
  • 25