Message110762
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 <me@myProvider.net>'
msg['To'] = 'You <you@yourProvider.com>'
# 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') |
|
Date |
User |
Action |
Args |
2010-07-19 14:57:04 | vunruh | set | recipients:
+ vunruh, r.david.murray |
2010-07-19 14:57:04 | vunruh | set | messageid: <1279551424.02.0.281648352362.issue9298@psf.upfronthosting.co.za> |
2010-07-19 14:57:01 | vunruh | link | issue9298 messages |
2010-07-19 14:57:01 | vunruh | create | |
|