简体   繁体   中英

Python smtplib module: Attachment not successfully sent to multiple recipients

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM