2012-07-17 2 views
4

perl 스크립트에서 전자 메일을 보내려고하지만 SMTP 서버에 연결하는 데 시간이 너무 많이 걸립니다. MailCatcher-https://github.com/sj26/mailcatcher/ - 기본 설정 (localhost : 1025)으로 실행 중입니다.Perl Mail :: Sendmail cant가 SMTP 서버에 연결

MailCatcher가 실행 중이고 다른 서비스와 메일을 보낼 수 있습니다. 무엇이 잘못 될 수 있는지에 대한 단서가 있습니까? (또한 인터넷 :: SMTP와 메일을 보낼 시도했지만 그 또한 연결 실패)

print "Testing Mail::Sendmail version $Mail::Sendmail::VERSION\n"; 

my %mail = (
    To  => '[email protected]', 
    From => '[email protected]',  
    Subject => 'Test message' 
); 

$mail{server} = 'localhost:1025'; 

$mail{'mESSaGE : '} = "The message key looks terrible, but works."; 

print Dumper(%mail); 

if (sendmail %mail) { print "Mail sent OK.\n" } 
else { print "Error sending mail: $Mail::Sendmail::error \n" } 

출력

Testing Mail::Sendmail version 0.79 
Default server: localhost 
Default sender: 
$VAR1 = 'Subject'; 
$VAR2 = 'Test message'; 
$VAR3 = 'server'; 
$VAR4 = 'localhost:1025'; 
$VAR5 = 'To'; 
$VAR6 = '[email protected]'; 
$VAR7 = 'message : '; 
$VAR8 = 'The message key looks terrible, but works.'; 
$VAR9 = 'From'; 
$VAR10 = '[email protected]'; 
Error sending mail: connect to localhost failed (Connection refused) 
connect to localhost failed 
connect to localhost failed (Connection refused) 
connect to localhost failed 
connect to localhost failed (Connection refused) no (more) retries! 

편집 :

가 mailcatcher 다른 포트 및 얻지 못한에서 실행 된 정보가있다 ' 내가 25 일에 시작하려 할 때 오류가 발생했습니다.

+0

포트 1025? 25 아닌가요? –

+0

MailCatcher는 기본적으로 1025에서 SMTP 서버를 실행합니다. – Marklar

답변

3

전자 메일의 헤더에 메일 서버와 포트를 설정하지 마십시오. 오히려 당신은이 %mailcfg 해시 설정 :

use Mail::Sendmail qw(sendmail %mailcfg) 
$mailcfg{port} = 1025; #localhost is already the default server... 
1

당신이 하나를 시도 할 수 있습니다 .. 그것은 나를 위해 일한 ..

use strict; 
use warnings; 
use Email::Sender::Simple qw(sendmail); 
use Email::Sender::Transport::SMTP(); 
use Email::Simple(); 
use Email::Simple::Creator();  

my $smtpserver = 'server'; 
my $smtpport = 25;  
my $smtpuser = 'User_Name'; 
my $smtppassword = 'pass';   
my $transport = Email::Sender::Transport::SMTP->new({ 
    host => $smtpserver, 
    port => $smtpport,    
    sasl_username => $smtpuser,  
    sasl_password => $smtppassword, 
});    

my $email = Email::Simple->create(header => [ 
     To  => '[email protected]', 
     From => '[email protected]', 
     Subject => 'Hello there!', 
    ], body => "This is one actually worked !!\n",    
);    

sendmail($email, { transport => $transport }); 
?>