Vance Unruh added the comment:
Here's code that attaches the pdf file the two different ways. Both attachments
are OK when I read the mail on OSX, but one is corrupt when read with Windows
Mail on Vista. I wasn't sure what to do with the actual sending of the mail to
the server. You'll have to change the code to use your account or something.
def emailReport(pdf):
"""Email the report as multi-part MIME"""
from email.mime.multipart import MIMEMultipart
msg = MIMEMultipart()
msg['Subject'] = 'Corrupt PDF'
msg['From'] = 'Me '
msg['To'] = 'You '
# Add the PDF the easy way that fails:
from email.mime.application import MIMEApplication
fp = open(pdf, 'rb')
part = MIMEApplication(fp.read(),"pdf")
fp.close()
part.add_header('Content-Disposition', 'attachment',filename='This one
fails.pdf')
msg.attach(part)
# Add the PDF the hard way using the legacy base64 encoder
from email.mime.base import MIMEBase
part = MIMEBase("application","pdf")
part.add_header('Content-Transfer-Encoding', 'base64')
part.add_header('Content-Disposition', 'attachment',filename='This one
works.pdf')
import base64
fp = open(pdf, 'rb')
part.set_payload(str(base64.encodebytes(fp.read()),'ascii'))
fp.close()
msg.attach(part)
# Send the email
from smtplib import SMTP
server = SMTP('smtpauth.provider.net')
server.login(user,password)
server.sendmail(msg['From'], recipient, msg.as_string())
server.quit()
emailReport('bugs.python.org_issue9298.pdf')
--
Added file: http://bugs.python.org/file18064/bugs.python.org_issue9298.pdf
___
Python tracker
<http://bugs.python.org/issue9298>
___
___
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com