views:

834

answers:

3

How can I send mail to Gmail using Perl? Here's what I'm trying:

my $mailer = Email::Send->new(
    {
        mailer      => 'SMTP::TLS',
        mailer_args => [
            Host     => 'smtp.gmail.com',
            Port     => 587,
            User     => 'xxx',
            Password => 'xxx',
        ]
    }
);

use Email::Simple::Creator;    # or other Email::

use File::Slurp;
@arrIrc = read_file("$ircFile");
my $email = Email::Simple->create(
    header => [
        From    => 'xxx',
        To      => "$configList{email}",
        Subject => "The summary of logfile $channelName",
    ],
    body => "@arrIrc",
);
+1  A: 

You can use MIME::Lite to compose a message, which you then send to your local sendmail process. However, in order to talk to gmail's servers you need to have SSL certificates set up. There's probably more detailed instructions for that on superuser.

Ether
So you mean to say that once the SSL certificates are set up manually then I can send mail with attachment using MIME::Lite to gmail (provided I had given username and password of gmail account). Right?
+4  A: 

Use Net::SMTP::SSL to talk to GMail.

See MIME::Lite inline images on Perlmonks for an example.

Sinan Ünür
I wonder whether I can have attachment with Net::SMTP::SSL?
SMTP is for transport. If you have a correctly formatted message (Mime-Lite can help you with that), then it will happily send whatever you hand it.
Sinan Ünür
+2  A: 

If you want to send mail to Gmail, you do the same thing you would do to send mail anywhere. If you want to send mail through Gmail, there is the Email::Send::Gmail module. Merely typing your question in Google led me to Sending Mail Through Gmail with Perl by Mark Sanborn.

brian d foy