Getting "empty" attachment with smtplib

Tobiah toby at tobiah.org
Wed Nov 14 12:58:30 EST 2012


I just found out that the attachment works fine
when I read the mail from the gmail website.  Thunderbird
complains that the attachment is empty.

Thanks,

Toby

On 11/14/2012 09:51 AM, Tobiah wrote:
> I've been sending an email blast out with smtplib and
> it's been working fine. I'm attaching an html doc with
>
> msg.attach(MIMEText(email, 'html'))
>
> and it displays fine. Now I need to attach a .pdf
> doc, but Thunderbird complains that the attachment
> is empty. When I view the source of the email, the
> headers look ok to me, and a large base64 looking
> mess follows:
>
> --===============0152408622==
> Content-Type: application/pdf
> MIME-Version: 1.0
> Content-Transfer-Encoding: base64
> Content-Disposition: attachment; filename="tics.pdf"
>
> JVBERi0xLjYNJeLjz9MNCjE0IDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MIDExNzk1My9PIDE2L0Ug
> MTEyNjE3L04gMS9UIDExNzY0My9IIFsgNjA2IDI1M10+Pg1lbmRvYmoNICAgICAgICAgICAgICAg
> DQo2MSAwIG9iag08PC9EZWNvZGVQYXJtczw8L0NvbHVtbnMgNS9QcmVkaWN0b3IgMTI+Pi9GaWx0
> ZXIvRmxhdGVEZWNvZGUvSURbPDg4RkMxMTM2QjQ3RDhEQzRFMjkxQkEzRDJGNEIyODBBPjxGRTNC
> RkM3MjNFMDg3QzRCQUEyNTUzMkM5NEI5QjNCOT5dL0luZGV4WzE0IDc4XS9JbmZvIDEzIDAgUi9M
>
> and so on. I've tried a few recipes, and this is the one I'm trying now:
>
> pdf = MIMEApplication(pdf_data, 'pdf')
> pdf.add_header('Content-Disposition','attachment', filename = 'tics.pdf')
> msg.attach(pdf)
>
> Any help is appreciated. Also, if anyone has a working recipe, I'd like to
> see it.
>
> Thanks!
>
> Tobiah




More information about the Python-list mailing list