my $from = 'email@gmail.com'; my $to = 'email@email.com'; my $Subject = 'subj'; my $filepath = 'c:\programming'; my $txttype = 'text/plain'; my $filenm = 'txt.txt'; my $user = 'username'; #confused if I need to use my email address as +username or just username my $passwd = 'pass'; #--------- NET::SMTP::SERVER ---------- my $smtp = Net::SMTP::Server->new( Host => 'smtp.gmail.com', Hello => 'smtp.gmail.com', Timeout => 30, Debug => 1, Auth => ($user, $passwd), ); $smtp->mail("email\@gmail.com"); $smtp->recipient("email\@gmail.com", \ "email\@email.com"); $smtp->datasend("From: email\@gmail.com"); $smtp->datasend("To: email\@email.com"); $smtp->datasend("Subject: This is a test"); $smtp->datasend("\n"); $smtp->datasend("blahblah"); $smtp->dataend; $smtp->quit; # This resulted in an error that the program wsa unable to connect to +gmail #------------ MAIL::WEBMAIL::GMAIL -------- my $gmail = Mail::Webmail::Gmail->new( username => $user, password => +$passwd ); $gmail->send_message( to => $to, subject => 'Test Message', msgbody => + 'This is a test.' ); # This completed without error, but I never recieved an email #------------ MAIL::SENDER ----------------- my $sender=Mail::Sender->new; if ($sender->MailMsg({ smtp => 'smtp.gmail.com', from => 'email@gmail.com', to => 'email@email.com', subject => 'test email', msg => 'testing email', auth => 'LOGIN', authid => $user, authpwd => $passwd, }) < 0) { die "$Mail::Sender::Error\n"; } print "Mail sent OK."; # This was not able to connect either #------------ MIME::LITE -------------------- my $msg = MIME::Lite->new( From => $from, To => $to, Subject => $Subject, Data => "Blah blah" #smtp => 'smtp.gmail.com' ); $msg->attr("content-type" => "multipart/mixed"); #for each attachment: $msg->attach( Type => "text/plain", Path => $filepath, Filename => $filenm, Disposition => "attachment" ); MIME::Lite->send('smtp','smtp.gmail.com', Port => '465',Debug => '1', +Hello => 'gmail.com' , User=>$user, Password =>$passwd, Timeout => 60 +); $msg->send(); # This resulted in not being able to connect to gmail either
In reply to What is the easiest/most efficient way to send an email w/ attachment through gmail by nervousmark
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |