我有一个使用Java使用我们自己的SMTP服务器发送电子邮件的场景。我有一个应用程序部署在Tomcat 6上。从Perl发送邮件但不从Java发送邮件
- 当我们使用GMail SMTP时,发送电子邮件的功能起作用。
- 当我尝试使用我们自己的服务器时,该功能不起作用。
我收到以下错误
MailException occured while sending emailMail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: 172.16.16.1, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: 172.16.16.1, port: 25;
nested exception is:
java.net.ConnectException: Connection timed out
的问题是,一切从使用Perl脚本相同的证书和配置参数正常工作。
我在Debain系统上。
我怀疑是否存在某种访问权限问题。我是Linux新手,知识非常有限。
任何人都可以请帮忙吗?
Perl脚本
粘贴下面的Perl脚本参考
#!/usr/bin/env perl
# System Modules
use strict;
use warnings;
use Mail::Sender;
my $subject = q/Testing Mail Server./;
my $smtp = q/localhost/;
my $from = 'Test <[email protected]>';
my $to = '[email protected]';
my $msg = q/Hi Testing.../;
my $auth = q{};
my $authid = q{};
my $authpwd = q{};
eval {
sendmail($smtp, $from, $to, q{}, $subject, $msg, $auth, $authid, $authpwd);
};
if ([email protected]) {
print STDERR "Confirmation Mail Sending to $to Failed.\n";
print STDERR 'ERROR: ' . [email protected];
}
sub sendmail {
my ($smtp, $from, $to, $bcc, $subject, $msg, $auth, $authid, $authpwd) = @_;
my $sender = new Mail::Sender { smtp => $smtp, from => $from };
$sender->Body(0, 0, 'text/html');
my $result = $sender->MailMsg(
{
replyto => '[email protected]',
to => $to,
bcc => $bcc,
subject => $subject,
msg => $msg,
auth => $auth,
authid => $from,
authpwd => $authpwd,
}
);
if ($result < 0) {
die "$Mail::Sender::Error\n";
}
}
Perl脚本和Tomcat在同一台机器上。事实上与Tomcat在同一个目录中。 – 2012-03-23 10:19:36
Perl脚本实际上很简单,我已经将它添加到问题中以供参考。 – 2012-03-23 10:27:36
@SB。 - 正如我所建议的那样,剧本并没有按照你的想法去做。 – 2012-03-23 10:32:10