我正在尝试实施从perl发送来自gmail的电子邮件的步骤。 我正在尝试使用不同的模块:
使用来自互联网的示例但没有任何效果
这是我写的脚本:
1)。
#!C:\Perl64\bin\perl.exe
use strict;
use warnings;
use Email::Send;
use Email::Send::Gmail;
use Email::Simple::Creator;
my $email = Email::Simple->create(
header => [
From => 'xxx@gmail.com',
To => 'zzz@yahoo.com',
Subject => 'alert! please have a look',
],
body => 'Dear Ionut, Please have a look on the following error. Thank you, the server.',
);
my $sender = Email::Send->new(
{ mailer => 'Gmail',
mailer_args => [
username => 'xxx@gmail.com',
password => '12345678',
]
}
);
eval {$sender->send($email)};
die "Error sending mail: $@" if $@;
收到的错误:
Error sending mail: Email::Send::Gmail: error connecting to server smtp.gmail.com at C:\Users\ipreda\perl5\lib\perl5/Email/Send.pm line 256.
2)。
use strict;
use warnings;
use Mail::Sendmail;
my $to_list = 'xxx@yahoo.com';
my $cc_list = 'aaa@yahoo.com';
my $bcc_list = '';
my $email = "Dear you, \n\nPlease have a look on the following error. \n\nThank you, \n\nthe server.\n";
my $MailFrom = 'aaa@yahoo.com';
my $subject = "alert! please have a look";
my $message = "module test";
%mail = (
To => $to_list,
From => $MailFrom,
Bcc => $bcc_list,
Cc => $cc_list,
Subject => $subject,
Message => $message
);
$mail{Smtp} = 'smtp.gmail.com';
sendmail(%mail);
错误是
Global symbol "%mail" requires explicit package name at D:\_Perl - tutorials\send_email_1.pl line 12
Global symbol "%mail" requires explicit package name at D:\_Perl - tutorials\send_email_1.pl line 20
Global symbol "%mail" requires explicit package name at D:\_Perl - tutorials\send_email_1.pl line 21
Execution of D:\_Perl - tutorials\send_email_1.pl aborted due to compilation errors.
3)。
use strict;
use warnings;
use Net::SMTP::TLS;
my $smtp = new Net::SMTP::TLS(
'smtp.gmail.com',
Port => 587,
User => xxx@gmail.com',
Password=> '12345678',
Timeout => 60
);
# -- Enter email FROM below. --
$smtp->mail('xxx@gmail.com');
# -- Enter recipient mails addresses below --
my @recipients = ('aaa@yahoo.com', 'bbb@yahoo.com');
$smtp->recipient(@recipients);
$smtp->data();
#This part creates the SMTP headers you see
$smtp->datasend('To: aaa@yahoo.comn');
$smtp->datasend("From: me n");
$smtp->datasend("Content-Type: text/html \n");
$smtp->datasend("Subject: A Test Mail");
# line break to separate headers from message body
$smtp->datasend("\n");
$smtp->datasend("This is a test mail body");
$smtp->datasend("\n");
$smtp->dataend();
$smtp->quit;
错误
Connect failed :IO::Socket::INET: connect: 10060
at D:\_Perl - tutorials\send_email_2.pl line 6.
我想这不是代码,但可能是防火墙中的一些设置?!
任何人都可以告诉我应该修改哪些设置,如果我的猜测正确或者指出错误,请?
非常感谢!