By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,866 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,866 IT Pros & Developers. It's quick & easy.

attach a pdf file to an email

P: n/a
Hi, I am writing a simple program that sends emails with attachments.

I could use "MIMEImage" for .png and then attach it to an
"MIMEMultipart" object. But I couldn't or don't know how to attachment
a .pdf or something else to my emails.

I'm new to python, could somebody help me about that?
Thank You,
kychan

Dec 19 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
here is my code for Excel
outer = MIMEMultipart()
outer['Subject'] = header.decode('cp1251').encode('koi8-r')
outer['To'] = baseParam['mailto']
outer['From'] = baseParam['mailfrom']
outer.preamble = ''
# To guarantee the message ends with a newline
outer.epilogue = ''

outer.attach(MIMEText('Weekly report', 'plain', 'koi8-r'))

fp = open(reportFileName, 'rb')
msg = MIMEBase('application', 'octet-stream')
msg.set_payload(fp.read())
fp.close()
# Encode the payload using Base64
Encoders.encode_base64(msg)
# Set the filename parameter
msg.add_header('Content-Disposition', 'attachment',
filename=header.decode('cp1251').encode('koi8-r') + '.xls')
outer.attach(msg)

server = smtplib.SMTP(baseParam['server'], baseParam['port'],
'localhost')
#server.set_debuglevel(1)
server.sendmail(baseParam['mailfrom'], baseParam['mailto'],
outer.as_string())
server.quit()

Dec 19 '05 #2

P: n/a
no*******@hotmail.com wrote:
Hi, I am writing a simple program that sends emails with attachments.

I could use "MIMEImage" for .png and then attach it to an
"MIMEMultipart" object. But I couldn't or don't know how to attachment
a .pdf or something else to my emails.

I'm new to python, could somebody help me about that?
Thank You,
kychan


Here is a great helper class that I have used for several
years. I didn't write it, but it has worked fine. Even if
you want to write your own, it should help as a guide.

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

Larry Bates
Dec 19 '05 #3

P: n/a
Thanks
I think I should use MIMEBase for any file.

Dec 19 '05 #4

P: n/a
also the code are useful thanks again

Dec 19 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.