1
我想從我的Gmail帳戶發送電子郵件,並且得到錯誤:Perl的SMTP電子郵件發送不工作
Error sending email: Connect failed :IO::Socket::INET: connect: timeout at /home/tas/perl5/lib/perl5/Email/Send/SMTP/TLS.pm line 45
我試過幾個不同的電子郵件不會忽略(Gmail和其他人),但結果是一樣的。
我用這個代碼:
#!/usr/bin/perlml
use Email::Send;
print "Content-type: text/html\n\n";
my $mailer = Email::Send->new({
mailer => 'SMTP::TLS',
mailer_args => [
Host => 'smtp.gmail.com',
Port => 587,
User => '[email protected]',
Password => 'XXXXXXXXX',
Hello => 'fayland.org',
]
});
use Email::Simple::Creator; # or other Email::
my $email = Email::Simple->create(
header => [
From => '[email protected]',
To => '[email protected]',
Subject => 'test',
],
body => 'test',
);
eval { $mailer->send($email) };
die "Error sending email: [email protected]" if [email protected];
這裏有什麼問題?任何其他方式使用smtp發送電子郵件?
您似乎沒有仔細閱讀錯誤消息。一個'connect:timeout'應該與你發送的地址無關。您到SMTP服務器的連接超時,這意味着您的Internet連接上有一個防火牆可以降低您的出站流量......與您的代碼或您使用的模塊無關。解決該問題。試試'telnet smtp.gmail.com 587'或'openssl s_client -connect smtp.gmail.com:587'。你看到了什麼? –
@ Michael-sqlbot,以及如何在服務器上運行它?我只有ftp和cpanel acsess到我的網站... – adrenalin
你也可以使用['Email :: Send :: SMTP :: Gmail'](https://metacpan.org/pod/Email::Send::SMTP :: Gmail帳戶)。我已經測試過[這裏](http://www.perlmonks.org/?node_id=1170831)。如果您不想更改您的Gmail帳戶設置以允許訪問安全性較低的應用,則可以嘗試使用OAuth2身份驗證,但我無法找到如何在Perl中執行此操作。儘管我使用[python-oauth2](https://github.com/joestump/python-oauth2)設法在Python中完成。 –