attach a pdf file to an email

Pelmen pelmenmail at mail.ru
Mon Dec 19 13:40:40 CET 2005


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()




More information about the Python-list mailing list