in reply to Re: Send a mail in Win32 with Gmail
in thread Send a mail in Win32 with Gmail
use strict; use warnings; use FindBin; use Net::SMTP::TLS; use MIME::Lite; use lib ("$FindBin::Bin/CPAN"); my $msg = MIME::Lite->new( From => 'me@gmail.com', To => 'you@gmail.com', Subject => 'A message with 2 parts...', Type => 'multipart/mixed', ); #$msg->attach( # Type => 'TEXT', # Data => "Here's the GIF file you wanted", #); # $msg->attach( # Type => 'plain/txt', # Path => 'Log/output.log', # Filename => 'output.log', # ); my $mailer = new Net::SMTP::TLS( 'smtp.gmail.com', Hello => 'smtp.gmail.com', Port => 587, User => 'me@gmail.com', Password=> 'my-pwd'); $mailer->mail('me@gmail.com'); $mailer->to('you@gmail.com'); $mailer->data; $mailer->datasend($msg->as_string); $mailer->dataend; $mailer->quit;
Any suggestion is welcome!use Net::SMTP::SSL; sub send_mail { my $to = $_[0]; my $subject = $_[1]; my $body = $_[2]; my $from = 'me@gmail.com'; my $password = 'my_pwd'; my $smtp; if (not $smtp = Net::SMTP::SSL->new('smtp.gmail.com', Port => 465, Debug => 1)) { die "Could not connect to server\n"; } $smtp->auth($from, $password) || die "Authentication failed!\n"; $smtp->mail($from . "\n"); my @recepients = split(/,/, $to); foreach my $recp (@recepients) { $smtp->to($recp . "\n"); } $smtp->data(); $smtp->datasend("From: " . $from . "\n"); $smtp->datasend("To: " . $to . "\n"); $smtp->datasend("Subject: " . $subject . "\n"); $smtp->datasend("\n"); $smtp->datasend($body . "\n"); $smtp->dataend(); $smtp->quit; } # Send away! &send_mail('you@gmail.com', 'Server just blew up', 'Some more detail') +;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Send a mail in Win32 with Gmail
by ltriant (Scribe) on Jun 11, 2010 at 00:07 UTC | |
|
Re^3: Send a mail in Win32 with Gmail
by marto (Cardinal) on Jun 11, 2010 at 08:22 UTC | |
by saintex (Scribe) on Jun 11, 2010 at 11:00 UTC | |
by marto (Cardinal) on Jun 11, 2010 at 11:07 UTC | |
by Anonymous Monk on Jun 11, 2010 at 11:11 UTC | |
by saintex (Scribe) on Jun 11, 2010 at 13:06 UTC | |
by marto (Cardinal) on Jun 11, 2010 at 13:14 UTC |