我一直在摸索着如何從Windows 7上的Perl發送電子郵件。我無法安裝任何Perl模塊,主動Perl安裝。 (這意味着Mime :: Lite,Email :: Sender和Mail :: Sendmail都不在表格中)在Windows 7上使用Perl發送電子郵件,無需安裝模塊
我能找到的唯一電子郵件發送模塊似乎是Net :: SMTP,但我一直無法弄清楚如何正確使用它。我不太瞭解SMTP服務器的功能,更不用說它們是如何工作的。我發現發送郵件的每一篇文章都建議使用我不具備的不同模塊。
我看到another post建議使用Net :: SMTP :: SSL連接到Gmail,但我沒有SSL模塊。
這是一些代碼,我到目前爲止,我試圖使用Gmail作爲我的SMTP服務器:
use Net::SMTP;
$smtp = Net::SMTP->new('smtp.gmail.com'); # connect to an SMTP server
$smtp->mail('[email protected]'); # use the sender's address here
$smtp->to('[email protected]'); # recipient's address
$smtp->data(); # Start the mail
# Send the header.
$smtp->datasend("To: toAddress\@test.com\n");
$smtp->datasend("From: myAddress\@gmail.com\n");
$smtp->datasend("Subject: Test email\n");
$smtp->datasend("\n");
# Send the body.
$smtp->datasend("Hello, World!\n");
$smtp->dataend(); # Finish sending the mail
$smtp->quit; # Close the SMTP connection
我不斷收到錯誤:
Can't call method 'mail' on an undefined value
這我假設手段它無法連接到SMTP服務器。我怎樣才能解決這個問題?
也有任何其他模塊標準與活動Perl更容易使用?
我真的在尋找類似於Linux SENDMAIL命令的東西,它非常簡單,甚至不需要你連接或認證任何東西。 Linux SENDMAIL命令似乎甚至允許你組成你想要的任何「from」地址,這可能是非常危險但很棒!
編輯
而且它不是我去通過Gmail的要求。這只是我想到的第一件事。
我知道我應該使用'strict'和'warnings',但是這僅僅是一個快速腳本來嘗試並獲得它的工作。我儘可能保持它儘可能接近文檔中的示例。 – tjwrona1992 2015-02-05 16:48:44
請參閱http://stackoverflow.com/q/11009844/176646 – ThisSuitIsBlackNot 2015-02-05 16:50:11
這實際上是我爲我的鏈接而發佈的帖子,我必須將它與另一個混合起來,我現在將修復該鏈接。正如你可以看到的那樣,這篇文章建議使用'Net :: SMTP :: SSL',這是我沒有的。我只有'NET :: SMTP'。 – tjwrona1992 2015-02-05 17:10:51