My Perl script監視Unix上的目錄,存儲更新其監視目錄時發送通知郵件的用戶列表。如何維護我的Perl腳本中的郵件收件人列表?
這是用於構建
dirmon.pl
my $subject = '...';
my $msg = '...';
my $sendto = '[email protected] [email protected] [email protected]';
my $owner = '[email protected]';
...
open my $fh, "|-", "mail", "-s", $subject, $owner, "-c", $sendto
or die "$0: could not start mail: $!";
print $fh $msg or warn "$0: print: $!";
close $fh;
所以,現在,爲每一個新用戶是 我要發送通知郵件給我需要轉到代碼並將它們添加到$sendto
。對我來說這很好,但我想稍後將該實用程序分發給用戶,並且不希望他們手動將地址添加到列表中,至少不要直接編輯Perl代碼。
有兩個備選方案,我能想到的
維護具有收件人列表中的外部文件。我可以添加一個標記,以便當用戶說
dirmon.pl -a [email protected]
時,電子郵件地址被附加到文件中,並且在下一次發送郵件時,郵件也會發送給此收件人(dirmon.pl -r [email protected]
將用戶從列表中刪除)。唯一的問題是我需要在腳本中增加一個外部文件,我正在儘量減少這個腳本。我可以在"Can a perl script modify itself?"的行上自行修改Perl代碼。我不確定這是否是一個好主意。
是第一種方式最好的方法嗎?有沒有更好的方法來維護收件人列表?
您可以創建一個郵件列表,並有腳本發佈改變了這一點。您的用戶可以根據需要訂閱/取消訂閱該列表。 – Fozi 2010-09-13 14:31:46
在郵件列表中的文本文件?名單在哪裏? – Lazer 2010-09-13 14:33:18
不,我的意思是郵寄名單作爲服務。 http://en.wikipedia.org/wiki/Electronic_mailing_list – Fozi 2010-09-13 14:37:00