简体   繁体   中英

perl Email::Send with gmail fails with images

this question is related to HTML image not showing in Gmail , but the answers there do not (or no longer) work.

the problem is that my perl program (below) fails when my html-formatted messages that I want to send off as soon as an img tag is included. it does not matter whether the image itself is served from the google drive or not. I am guessing that I am running into a novel gmail restriction (my script used to work), but I am not sure.

(of course, this problem is not that my recipients do not see the image; it is that the sending perl script aborts with an error---unfortunately, not with more information explaining to me why it is an error. of course, I understand that my recipients need to agree to view images to prevent tracking.)

so here are my questions:

  1. is this a gmail or a perl module problem?

  2. is it possible to send images, so that if my recipients want to see images from my website (preferably not just images from my google drive as in my example below), they can agree to see this?

  3. is it possible to get a better error message from google about why it fails?

here is the [almost] working code:

#!/usr/bin/perl -w
use strict;
use warnings;

use Email::MIME::CreateHTML;
use Email::Send;
use Email::Send::Gmail;

my $toemail = 'ivo.welch@gmail.com';
my $subject = 'testing image mailing';
my $bodytext= '<html> <body> fails: <img src="https://drive.google.com/open?id=1K4psrWWolTSqx_f6MQP-T1-FMFpegT1Trg" alt="photo" />  </body> </html>\n';

use readcredentials;
my $gmailaccount= readcredentials( 'account' );
my $gmailuserlogin= readcredentials( 'userlogin');
my $gmailpasswd= readcredentials( 'gmailpassword');

eval {
  my $message = Email::MIME->create_html(
                                         header => [
                                                    From   => $gmailaccount,
                                                    To      => $toemail,
                                                    Subject => $subject,
                                                   ],
                                         body => $bodytext,
                                        );

  my $sender = Email::Send->new(
                                {   mailer      => 'Gmail',
                                    mailer_args => [
                                                    username => $gmailuserlogin,
                                                    password => $gmailpasswd,
                                                   ]
                                }
                               );

  $sender->send($message);
};
warn "Error sending email: $@" if $@;

print STDERR "emailed!\n";

I ran your script, with some modifications to remove the dependency on readcredentials to make it run in my environment, and the email was delivered with no problem. Problems could be:

  1. You could have some problems with your gmail credentials.
  2. The script downloads and attaches the image, so perhaps your local environment is preventing the image from being downloaded.

But without your specific error message, it's hard to diagnose any further.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM