我正嘗試使用Perl發送電子郵件。基本上我有一個Perl腳本,可以以很好的格式打印報告。我希望通過電子郵件發送該報告。我怎樣才能做到這一點?使用Perl發送電子郵件
回答
MIME::Lite是許多人使用的強大模塊。它很容易使用,包括如果你想附加文件。
use MIME::Lite;
my $msg = MIME::Lite->new(
From => $from,
To => $to,
Subject => $subject,
Type => 'text/plain',
Data => $message,
);
$msg->send;
由於它使用默認sendmail
(而不是SMTP),你甚至都不需要進行配置。
我知道這個答案是舊的,但MIME :: Lite文檔現在說:'等待! MIME :: Lite不被其當前維護者推薦。有許多替代方法,比如Email :: MIME或MIME :: Entity和Email :: Sender,你應該使用它。 MIME :: Lite繼續累積怪異的錯誤報告,並且由於更好的替代方案的可用性,它不會接收大量的重構。請考慮使用別的東西。' – ThisSuitIsBlackNot
值得一提的是,如果你碰巧有你的機器上Outlook和CPAN觀模塊:
# create the object
use Mail::Outlook;
my $outlook = new Mail::Outlook();
# start with a folder
my $outlook = new Mail::Outlook('Inbox');
# use the Win32::OLE::Const definitions
use Mail::Outlook;
use Win32::OLE::Const 'Microsoft Outlook';
my $outlook = new Mail::Outlook(olInbox);
# get/set the current folder
my $folder = $outlook->folder();
my $folder = $outlook->folder('Inbox');
# get the first/last/next/previous message
my $message = $folder->first();
$message = $folder->next();
$message = $folder->last();
$message = $folder->previous();
# read the attributes of the current message
my $text = $message->From();
$text = $message->To();
$text = $message->Cc();
$text = $message->Bcc();
$text = $message->Subject();
$text = $message->Body();
my @list = $message->Attach();
# use Outlook to display the current message
$message->display;
# Or use a hash
my %hash = (
To => '[email protected]',
Subject => 'Blah Blah Blah',
Body => 'Yadda Yadda Yadda',
);
my $message = $outlook->create(%hash);
$message->display(%hash);
$message->send(%hash);
注意,.invalid TLD是不是真實的,所以上面的地址將無法實現。無論如何,我已經在模塊中提供了一些體面的解釋 - 這會發送一條消息!
@Grep培根我試過這段代碼,但錯誤是'不能調用方法'從'在mail.pl第24行未定義的值「。在這段代碼中。我能做什麼? – mkHun
@Hussain不要完全按照原樣運行此代碼 - 這只是一個CPAN部分,顯示您可以執行的所有方法。在第24行之前,它先運行的代碼(),next(),last()和previous()。您不應該將所有這些背對背運行......可能會嘗試訪問沒有From()的內容。 另外,在所有選擇當前文件夾兩次之前......不妨將它清理乾淨,只需抓住「收件箱」即可。 – PinkElephantsOnParade
嗨,我遇到了這個問題,似乎'$ outlook = new Mail :: Outlook()'返回undef ...爲什麼是這樣?我已經安裝了模塊,我有Outlook 2007 ...我如何創建$ outlook對象? – catzilla
如果sendmail的配置的機器沒有,我通常使用Mail::Sendmail
use Mail::Sendmail;
%mail = (smtp => 'my.isp.com:25',
to => '[email protected]',
from => '[email protected]',
subject => 'Automatic greetings',
message => 'Hello there');
sendmail(%mail) or die;
+1 ::這對我有用。我使用了'localhost:25' –
最簡單的方式,而不CPAN庫:
#!/usr/bin/perl
$to = '[email protected]'; # to address
$from = '[email protected]'; # from address
$subject = 'subject'; # email subject
$body = 'Email message content';# message
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL $body;
close(MAIL);
print "Email Sent Successfully to $to\n";
- 1. 使用perl從原始電子郵件分開發送電子郵件
- 2. 發送電子郵件使用perl郵件/發件人與HTML正文部分
- 3. 使用send_dbmail發送電子郵件表中的電子郵件
- 4. vb.NET SmtpClient無法使用電子郵件發送電子郵件
- 5. 發送電子郵件使用PHP的電子郵件發送給多人
- 6. 發送電子郵件操作不發送電子郵件
- 7. PHP發送電子郵件多次發送電子郵件
- 8. 電子郵件不發送與perl MIME :: Lite使用smtp
- 9. 如何重試使用perl發送電子郵件
- 10. 如何使用Perl發送HTML電子郵件?
- 11. 用PHP郵件發送電子郵件()
- 12. 使用sendgird發送電子郵件
- 13. 使用Powershell發送Outlook電子郵件
- 14. 使用JavaScript發送電子郵件
- 15. 發送電子郵件使用net/SMTP
- 16. 使用codeigniter發送電子郵件
- 17. 使用RoR發送電子郵件
- 18. 使用Wordpress發送電子郵件
- 19. 發送電子郵件使用笨
- 20. 使用xampp發送電子郵件
- 21. 發送電子郵件使用Java
- 22. 使用OAuth發送電子郵件
- 23. 使用SMTP發送電子郵件
- 24. 使用EWS發送電子郵件
- 25. 發送電子郵件Mailgun使用Javascript
- 26. 自動發送電子郵件使用
- 27. 使用Sendgrid api發送電子郵件
- 28. 使用JSP發送電子郵件
- 29. 使用mailto發送電子郵件:URL
- 30. ORACLE使用SSL發送電子郵件
[?什麼是發送電子郵件的最好的Perl模塊(HTTP :(http://stackoverflow.com/questions/338896/what-is-the-best-perl-module-for-sending-email),[我應該使用哪個CPAN包發送郵件?](http:// stackoverflow。 com/questions/2919493/which-package-from-cpan-should-i-use-to-send-mail) – daxim
CPAN是你的朋友d,新的或舊的Perl。例如,嘗試[電子郵件::發件人](https://metacpan.org/module/Email::Sender)。好的文檔在[快速入門手冊](https://metacpan.org/module/Email::Sender::Manual::QuickStart)。 – asjo
使用Perl SMTP http://perldoc.perl.org/Net/SMTP.html –