简体   繁体   English

如何使用Perl通过Sendmail将同一封电子邮件发送给多个收件人?

[英]How do you send the same email to multiple recipients with Sendmail using Perl?

I have the following PERL script, but I can't seem to get it to send to more than one email at once. 我有以下PERL脚本,但似乎无法一次发送到多个电子邮件中。 How do I send to multiple emails, preferably as separate emails? 如何发送至多封电子邮件,最好是作为单独的电子邮件发送?

 open(SENDMAIL, "|/usr/lib/sendmail -oi -t") || die "Cannot open sendmail output"; print SENDMAIL <<"ENDENDEND"; From: <test\\@test.com> To: <test1\\@test1.com> Subject: report spam MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="DeathToSpamDeathToSpamDeathToSpam" This is a multi-part message in MIME format. --DeathToSpamDeathToSpamDeathToSpam Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit --DeathToSpamDeathToSpamDeathToSpam Content-Type: message/rfc822 Content-Disposition: attachment ENDENDEND while (<STDIN>) { print SENDMAIL ; } print SENDMAIL <<"ENDENDEND"; --DeathToSpamDeathToSpamDeathToSpam-- ENDENDEND close (SENDMAIL); 

Thanks! 谢谢!

Sending a mail by executing the sendmail program can do only a single mail at a time because that's how the sendmail program works: the mail gets piped into sendmail and the mail is done on EOF. 通过执行sendmail程序来发送邮件一次只能发送一封邮件,因为sendmail程序就是这样工作的:邮件通过管道传送到sendmail中,并且邮件在EOF上完成。 This means you need to invoke sendmail again for the next mail. 这意味着您需要为下一封邮件再次调用sendmail。

Another way would be to not execute sendmail for delivery but directly talk to a SMTP server using Net::SMTP or similar modules - this way you could also send multiple mails within a single SMTP connection. 另一种方法是不执行sendmail进行传递,而是使用Net :: SMTP或类似模块直接与SMTP服务器通信-这样,您还可以在单​​个SMTP连接中发送多个邮件。

EDIT: as noted in a comment by Andrzej A. Filip one call sendmail with the -bs option so that it works as a minimal SMTP server which expects communication with stdin and stdout. 编辑:正如Andrzej A.在评论中指出的那样,使用-bs选项使一次呼叫sendmail成为-bs因此它可以作为最小的SMTP服务器使用,期望与stdin和stdout通信。 This feature seems to be implemented also in the sendmail wrapper from Postfix which is probably more in use than the original sendmail . Postfix的sendmail包装器中似乎也实现了此功能,它可能比原始sendmail的使用率更高。
But, I'm not aware of any module which supports this mode of operation so you are on your own to setup the bidirectional communication with maybe IPC::Open2 and then speak the SMTP protocol including all the strange end of mail handling and escaping rules. 但是,我不知道有任何模块支持此操作模式,因此您需要自己设置与IPC :: Open2的双向通信,然后讲出SMTP协议,包括所有奇怪的邮件处理和转义规则。 It would be much easier to just talk SMTP to the mail server on localhost using Net::SMTP which already cares about all the protocol specific stuff and lets you just send the mails. 使用Net :: SMTP仅将SMTP与本地主机上的邮件服务器进行SMTP通讯就容易得多,该服务器已经在乎所有特定于协议的内容,并允许您仅发送邮件。

Adding "Cc: " seems to work in this instance. 在这种情况下,似乎可以添加“ Cc:”。

For some reason, using Bcc: or adding another To: email does NOT work, but Cc: seems to do it. 由于某些原因,使用“密件抄送:”或添加其他“收件人:”电子邮件不起作用,但“抄送:”似乎可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM