Adding Multiple Attachments to SMTP mail (msg.add_header)

E

EdWhyatt

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
 
L

Larry Bates

EdWhyatt said:
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

Take a look at the following:

http://motion.sourceforge.net/related/send_jpg.py

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52243

Larry Bates
 
C

Christos Georgiou

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.

The {doatt = doatt + 1} line is unneeded in the {for doatt in} loop. This
*might* be your problem, I didn't delve any deeper.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top