473,399 Members | 2,278 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

attach a pdf file to an email

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
4 6184
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
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
Thanks
I think I should use MIMEBase for any file.

Dec 19 '05 #4
also the code are useful thanks again

Dec 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: tabonni | last post by:
Hi I try to grab the checked files from HTML page and then send those PDF files as attachments. It can just send email, there are no PDF files attached. Can anybody point out my error? My...
4
by: neo | last post by:
I got a mdf file from my co-worker who just stopped SQL server and delete ldf file and give me a mdf file. if it was detached, it would work fine but it was just copied. Is there any way to...
6
by: a | last post by:
What is the best way to construct an email in python and also attach a html file the html file to be attached is not on disk, but should be dynamically constructed in the python script I want...
2
by: calebmichaud | last post by:
Hi I am having trouble understanding how to attach a file or files to a record. I want to (in form view0 allow the user to attach one or more than one file to the associated record, and then...
1
nirmalsingh
by: nirmalsingh | last post by:
hi everybody, my code for sending email is <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title>...
0
by: mmatchyn | last post by:
How do I attach an outlook email message as an attachment within another outlook email message. Right now I am using the following code. But I was wondering if there is a better way to do this...
7
by: RRsonawane11 | last post by:
Hello, Can anyone know how to write asp code to attach one file and email it to a specified email address. The attach file is the client choose from their Local Harddisk, just like we ...
1
by: rahia307 | last post by:
Hi I am using email function in php, and I want to attach a doc file with email. How can I attach doc file with email. If any one have idea about it please help me. Thanks
14
by: sreemathy2000 | last post by:
My requirement is to generate and attach a file and send in an email automatically. i have a existing functionality where i using the code below to write a CSV file in my local system. ...
9
by: dpatel75 | last post by:
I am trying to copy a database from a SQL 2000 SP3 Windows 2000 server to a 2005 SP2 Windows 2003 server. I am trying to use detach and attach method (have tried both within Management Studio and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.