PDF not previewing or downloading correctly from Gmail

Viewed 1160

I have an IMAP/SMTP account at a major email provider. I want to compose and send emails to multiple recipients. These emails will have one or more plain-text and/or PDF attachments. The PDF attachment I am using for testing is one I created with the "Export as PDF" function in Libre Office Writer -- functionality I have used many times before without problems.

I am using the Perl module Email::MIME to compose the email. Per that module's documentation, I have coded the composition of the email as follows:

use Email::MIME;
use IO::All;
use File::Basename;

my @parts = (
    Email::MIME->create(
        attributes => {
            filename     => basename($attachments{pdf}),
            content_type => "application/pdf",
            encoding     => "quoted-printable",
            name         => $attachments{pdf},
            disposition  => "attachment",
        },
        body => io( $attachments{pdf} )->binary->all,
    ),
    Email::MIME->create(
        attributes => {
            filename     => basename($attachments{text}),
            content_type => 'text/plain',
            name         => $attachments{text},
            disposition  => "attachment",
        },
        body => io( $attachments{text} )->all,
    ),
    Email::MIME->create(
        attributes => {
            content_type => "text/plain",
            charset      => "US-ASCII",
        },
        body => $this_body,
    ),
);

my $email = Email::MIME->create(
        header_str => [
            From => $from,
            To => [ $data->{$recipient}->{EmailAddress} ],
            Subject => $subject,
        ],
        parts      => [ @parts ],
);

The $email object is then passed off to an Email::Sender call and the messages are sent.

I am using four different email accounts to evaluate the results. One is my IMAP account; another is an account which forwards to my IMAP account; a third is a Yahoo! Mail account; and the fourth is a Gmail account.

With the code above, the results are as expected with the first three accounts -- where "as expected" means the body of the email, the plain-text attachment and the PDF attachment all open and render properly.

However, when I go to my Gmail account, two problems emerge with the PDF attachment:

* The PDF does not preview correctly in the Gmail web interface. A few words appear but are garbled.

* When I download the PDF to disk, the file size appears to be correct, but when I open the file it appears to be completely blank.

But there's one more observation: If when viewing the message in the Gmail web interface, I:

  • click on "More" (3 vertical dots)

  • then click on "Show Original"

  • then click "Download Original"

  • and then open the downloaded F<.eml> file in my Thunderbird client,

... then the PDF renders correctly.

So, can anyone advise as to why Gmail has problems with PDF attachments? Is there anything I can do to work around this?

0 Answers
Related