Adding Multiple Attachments to SMTP mail (msg.add_header)

EdWhyatt ed.whyatt at gmail.com
Fri Mar 10 09:08:37 EST 2006


Hi all, I hope there is someone out there who can help me out - it has
to be something obvious.

I am simulating mail traffic, and want to include multiple attachments
to my mail. I have created a temporary array containing a number of
files - for now just 2.

Debugging my code, I can see that I am correctly storing the files in
the array, and then 1 by 1 adding one file at a time to the message
header.

When the program is complete, the resultant mail has 2 attachments, as
hoped. However, it is the second file attached twice, rather than the
two unique files.

I attach my code for passing the information to  msg.add_header:

(AttNum = 2)

            for doatt in range(AttNum):
                msg.add_header('Content-Disposition', 'attachment',
filename=ATTselection[doatt])
                doatt = doatt + 1
                outer.attach(msg)

......
    body = MIMEText(Text)
    outer.attach(body)

Like I said, it is correctly sending the 2 seperate files from my
ATTselection array, but ultimately attaching the last file twice.

If anyone can help/suggest something please please let me know!

Thanks,
Ed




More information about the Python-list mailing list