我有一個由cron作業執行的perl腳本。在腳本的最後,它發出一封電子郵件讓我知道它完成了。當我通過命令行運行腳本時,它運行良好。當我通過cron運行時,一切正常,除了我從未收到電子郵件。我使用SENDMAIL發送電子郵件。我沒有root權限。我是一個標準用戶。有什麼想法嗎?Sendmail在Perl中工作,但不在CRON中
這是我用於SENDMAIL的腳本的一部分。
my $sendmail = "/usr/lib/sendmail -t";
my $to = "To: ". "me\@test.com\n";
my $from = "From: SUCCESS\@test.com\n";
my $reply_to = "Reply-to: me\@test.com\n";
my $content = "Updated the File\n";
my $subject = "Subject: SUCCESS \n";
my $cc = "";
open(SENDMAIL, "|$sendmail") or die "Cannot open $sendmail: $!";
print SENDMAIL $to;
print SENDMAIL $cc;
print SENDMAIL $from;
print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
在您的crontab中設置MAILTO,您的腳本不需要知道如何發送郵件。 – tripleee