http://www.perlmonks.org?node_id=1025015

Maktub has asked for the wisdom of the Perl Monks concerning the following question:

Hi.

Im' tring to send email with perl with my gmail account and insert a link in email's body.

I try many codes, but i can "send email with gmail NO Links" or "send html email but NO with gmail account". I google for two days, search in perlmonks but I cannot send email.

I use:

1. Email::Send and I can send email to gmail, but with simple body, no html.

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

2. I use Mime::Lite but i have this Error: SMTP auth() command not supported on smtp.gmail.com:587

MIME::Lite->send('smtp', 'smtp.gmail.com:587', Timeout => 60,AuthUser= +>$user, AuthPass=>$pass);$msg->send();

3. I use Net::SMTP::TLS but but i have this Error: Couldn't start TLS: Cannot determine peer hostname for verification

my $smtp = new Net::SMTP::TLS( 'smtp.gmail.com', Hello => 'test.org', Port => 587, User => $user, Password=> $password, Timeout => 30 );

Someone can help please?

Thanks in advice. Andrea

Replies are listed 'Best First'.
Re: Send Email to GMAIL with html body
by Corion (Patriarch) on Mar 23, 2013 at 08:59 UTC
      Hi. Thanks for reply.

      1. Mime::Lite link: no 64 bit system.

      2. Send a mail in Win32 with Gmail: i have linux.

      3. Send email from gmail SMTP: windows too.

      4. Net::SMTP_Auth: i don't know how to use it. Have you a sample code?

      Thanks. Andrea

        "1. Mime::Lite link: no 64 bit system."

        So?

        "2. Send a mail in Win32 with Gmail: i have linux."

        And?

        "3. Send email from gmail SMTP: windows too."

        Uh huh?

        "4. Net::SMTP_Auth: i don't know how to use it. Have you a sample code?"

        Had you actually read any of the links (or the replies with solutions) you've been given you'd know that the fact you're not on a 64bit system and not running Windows is irrelevant as none of the code requires either of these, and the sample code you ask for is included in the post linked to.

Re: Send Email to GMAIL with html body
by stefbv (Curate) on Mar 23, 2013 at 11:03 UTC

    At least you can use Email::Sender because:

    Email::Send is going away... well, not really going away, but it's being officially marked "out of favor."

    But I have good results using a higher level module: Mail::Builder::Simple.

    Regards, Stefan.

      Hi.

      Thanks for your reply.

      I write this code:
      use strict; use Email::Sender::Simple qw(sendmail); use Email::Simple; use Email::Simple::Creator; use Email::Sender::Transport::SMTP::TLS; use Email::Sender::Simple qw(try_to_sendmail); my $username = 'xxx@gmail.com'; my $password = 'xxx'; my $to = 'xxx@gmail.com'; my $from = 'yyy@gmail.com'; my $subject = 'Test'; my $transport = Email::Sender::Transport::SMTP::TLS->new( host => 'smtp.gmail.com', port => 587, username => $username, password => $password ); my $email = Email::Simple->create( header => [ To => $to, From => $from, Subject => $subject, ], body => "This message is short, but at least it's cheap.\n", ); sendmail($email, { transport => $transport });

      I can send simple text email. It works fine. What changes i need to send html email? If i use Mime i cannot use Mail::Sender.

      Can i create another type of $email that works with sendmail?

      Thanks. Andrea
Re: Send Email to GMAIL with html body
by hdb (Monsignor) on Mar 23, 2013 at 16:51 UTC

      I got it! Thansk to you all Monks!

      use strict; use Email::Sender::Simple qw(sendmail); use Email::Simple; use Email::Simple::Creator; use Email::Sender::Transport::SMTP::TLS; use Email::Sender::Simple qw(try_to_sendmail); use Email::Simple::Markdown; my $username = 'xxx@gmail.com'; my $password = 'xxx'; my $to = 'xxx@gmail.com'; my $from = 'yyy@gmail.com'; my $subject = 'Test'; my $transport = Email::Sender::Transport::SMTP::TLS->new( host => 'smtp.gmail.com', port => 587, username => $username, password => $password ); my $email = Email::Simple::Markdown->create( header => [ To => $to, From => $from, Subject => $subject, ], body => '[this](http://metacpan.org/search?q=Email::Simple::Ma +rkdown) is *amazing*', ); #print $email->as_string; sendmail($email, { transport => $transport });
      WOW! Andrea
Re: Send Email to GMAIL with html body
by Anonymous Monk on Mar 30, 2014 at 16:36 UTC
    I found a very simple fix - you just need to add the following statement into the header section of your Email::Simple->create
    # if email body is HTML - set content type, otherwise make TEXT my $email_type = ($email_body eq 'HTML' ? 'text/html' : 'TEXT'); my $email = Email::Simple->create( header => [ From => $opt_param->{email_from}, To => $opt_param->{email_to}, Subject => $subject, 'Content-Type' => $email_type, ], body => $message, );