Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33348 > unrolled thread
| Started by | Tobiah <toby@tobiah.org> |
|---|---|
| First post | 2012-11-14 09:51 -0800 |
| Last post | 2012-11-15 09:26 -0800 |
| Articles | 5 — 3 participants |
Back to article view | Back to comp.lang.python
Getting "empty" attachment with smtplib Tobiah <toby@tobiah.org> - 2012-11-14 09:51 -0800
Re: Getting "empty" attachment with smtplib Tobiah <toby@tobiah.org> - 2012-11-14 09:58 -0800
Re: Getting "empty" attachment with smtplib Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-15 04:54 +0000
Re: Getting "empty" attachment with smtplib Dieter Maurer <dieter@handshake.de> - 2012-11-15 08:37 +0100
Re: Getting "empty" attachment with smtplib Tobiah <toby@tobiah.org> - 2012-11-15 09:26 -0800
| From | Tobiah <toby@tobiah.org> |
|---|---|
| Date | 2012-11-14 09:51 -0800 |
| Subject | Getting "empty" attachment with smtplib |
| Message-ID | <oSQos.17607$h94.1407@newsfe02.iad> |
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
[toc] | [next] | [standalone]
| From | Tobiah <toby@tobiah.org> |
|---|---|
| Date | 2012-11-14 09:58 -0800 |
| Message-ID | <aZQos.6321$UE.1674@newsfe30.iad> |
| In reply to | #33348 |
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
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2012-11-15 04:54 +0000 |
| Message-ID | <50a4758b$0$11121$c3e8da3@news.astraweb.com> |
| In reply to | #33349 |
On Wed, 14 Nov 2012 09:58:30 -0800, Tobiah wrote: > 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. I suggest that you use Thunderbird to send yourself an email with a PDF attachment, then inspect how it is attached. How does that differ from the one you are sending from Python? When I try sending a PDF from mutt, I get: Content-Type: application/pdf Content-Disposition: attachment; filename="foo.pdf" Content-Transfer-Encoding: base64 I haven't tried opening that in Thunderbird, but I expect it should be okay. The only difference I see between what you are sending and mutt is that mutt doesn't include a MIME-version line. Perhaps Thunderbird doesn't like that? Wait... here's another thought. Perhaps Thunderbird doesn't know how to display the PDF file, and is giving a bogus error message? Can your Thunderbird display PDF files at all? Does it succeed when you use a different PDF file? What if you send a JPEG? -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Dieter Maurer <dieter@handshake.de> |
|---|---|
| Date | 2012-11-15 08:37 +0100 |
| Message-ID | <mailman.3712.1352965056.27098.python-list@python.org> |
| In reply to | #33349 |
Tobiah <toby@tobiah.org> writes: > 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. The MIME standard (a set of RFCs) specifies how valid messages with attachments should look like. Fetch the mail (unprocessed if possible) and look at its structure. If it is conformant to the MIME standard, then "Thunderbird" made a mistake; otherwise, something went wrong with the message construction. I can already say that "smtplib" is not to blame. It is (mostly) unconcerned with the internal structure of the message -- and by itself will not empty attachments.
[toc] | [prev] | [next] | [standalone]
| From | Tobiah <toby@tobiah.org> |
|---|---|
| Date | 2012-11-15 09:26 -0800 |
| Message-ID | <1B9ps.45628$c16.31159@newsfe10.iad> |
| In reply to | #33374 |
> I can already say that "smtplib" is not to blame. It is (mostly) unconcerned > with the internal structure of the message -- and by itself > will not empty attachments. On the advice of a co-worker, I tried using web2py's gluon.tools.Mail. It was easier to accomplish the attachment, and Thunderbird opened the .pdf just fine. Thanks for the suggestions. Tobiah
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web