Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

MIME::Lite inline images

by tmharish (Friar)
on Jul 30, 2009 at 11:34 UTC ( #784574=perlquestion: print w/ replies, xml ) Need Help??
tmharish has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to send out HTML emails using MIME::Lite with inline images.

Unfortunately Google does not display the images, instead it gives the "display images below" message. Is there anyway to get around this?

Here is the code I am using:
use warnings; use strict; use Carp; use MIME::Lite; use Net::SMTP::SSL; sub send_mail { # Function parameters - replaced by absolute values my $to = 'someone@gmail.com'; my $subject = "Test"; my $from = 'someoneelse@gmail.com'; my $password = "someoneelsepassword"; ## Beautification code my $from_mime = $from; my $count = @_; if( $count ) { my $from_name = shift; $from_mime = "\"$from_name\" <$from>"; } ## End of Beautification code my $msg = MIME::Lite->new ( From => "$from_mime" , To => "$to" , Subject => "$subject" , ); $msg->attach( Type => 'text/html', Data => qq{ <body> Here's <i>my</i> image: <img src="cid:cpan.png"> </body> }, ); $msg->attach( Type => 'image/png', Id => 'cpan.png', Path => 'cpan_banner.png', ); my $smtp; if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com', Port => 465, Debug => 1)) { croak "Could not connect to server\n"; } $smtp->auth( $from, $password ) || croak "Authentication failed!\n"; $smtp->mail($from . "\n"); my @recepients = split(/,/, $to); foreach my $recp (@recepients) { $smtp->to($recp . "\n"); } $smtp->data(); $smtp->datasend( $msg->as_string() ); $smtp->dataend(); $smtp->quit; } send_mail();

Comment on MIME::Lite inline images
Download Code
Replies are listed 'Best First'.
Re: MIME::Lite inline images
by marto (Bishop) on Jul 30, 2009 at 12:06 UTC

    This Gmail Blog post may be of interest regarding how this functionality works.

    Martin

      Thanks Martin

      Apparently I have to add a DKIM signature, with some DNS entry ...

      Off to figure that out.



Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://784574]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (18)
As of 2015-07-07 17:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (92 votes), past polls