2013-04-02 36 views
1

我試圖用附件發送郵件,我試過用Email::StuffMIME::Lite,在運行期間我得到一些錯誤,因爲Authentication failed或服務器沒有連接任何人都可以幫助我嗎? 對應的代碼是:如何使用perl與附件發送郵件?

use MIME::Lite; 
use Net::SMTP; 
### Adjust sender, recipient and your SMTP mailhost 
my $from_address = '[email protected]'; 
my $to_address = '[email protected]'; 
my $mail_host = 'smtp.gmail.com'; 

### Adjust subject and body message 
my $subject = 'A message with 2 parts ...'; 
my $message_body = "Here's the attachment file(s) you wanted"; 
my $your_file_zip = 'my.zip'; 

$msg = MIME::Lite->new (
    From => $from_address, 
    To => $to_address, 
    Subject => $subject, 
    Type =>'multipart/mixed' 
) or die "Error creating multipart container: $!\n"; 
MIME::Lite->send('smtp', 'smtp.gmail.com' , 
          Port =>465 , 
          Timeout=>320 , 
          Debug => 1 , 
          Hello => $mail_host, 
          User => $from_address, 
          Password => 'Thiyagu.04'); 
#$mime_msg->send() or die "Error sending message: $!\n"; 

#MIME::Lite->send('smtp',$mail_host,AuthUser=> $from_address, AuthPass=>"apssword"); 

$msg->send(); 

錯誤信息是;

SMTP Failed to connect to mail server: A connection attempt failed because the connected party did not properly respond aft 
    er a period of time, or established connection failed because connected host has failed to respond. 
    at mail.pl line 54. 

在此先感謝

+0

哪個包足以發送郵件附件? –

+0

它看起來像問題可能是您的機器的配置,而不是模塊。我建議更新您的問題,以包括您正在運行的系統以及您系統的相關程序的版本。 – 2013-04-02 11:05:10

+0

好吧夥計讓我們考慮這個版本的代碼! –

回答

1

錯誤信息似乎很清楚,我。問題在於你連接到郵件服務器 - 所以改變你使用的模塊不太可能實現任何有用的功能。我對Gmail的服務器設置不太瞭解,無法評論問題所在,但this page提供了一些可能遵循的建議。具體而言,您可以檢查Gmail帳戶是否啓用了「允許身份驗證」,並且您的郵件客戶端(Perl程序)正在使用SSL進行連接。

另外,如果您使用專門爲Gmail設計的電子郵件,這可能會更容易。 Email::Send::SMTP::Gmail看起來爲您的要求量身定做。