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