使用Perl问题将电子邮件转发到爱普生打印机"Email Print"



我目前正在使用Cpanel来设置一个电子邮件转发,该转发通过Cpanel电子邮件转发中的一个功能"管道到程序";。在这个perl脚本中,我获取标题并将其替换为Epson电子邮件打印地址,因为Epson打印机不喜欢直接转发。然而,我遇到的问题是,一次发送给多个用户会导致错误,并且不喜欢超过一个收件人。

我的代码如下:

#!/usr/bin/perl
use strict;
# Real email address for the printer
my $email = 'example@domain.com';
my $sm;
open($sm, "|/usr/sbin/sendmail -t");
my $in_header = 1;
while (my $line = <STDIN>) {
chomp $line;
# Empty line while in headers means end of headers
if ($in_header && $line eq '') {
$in_header = 0;
}
# Replace To: field if we're in headers
if ($in_header && $line =~ m/^To: /) {
$line = "To: $email";
}
# Pass through to sendmail
print $sm "$linen";
}
close($sm);

我有一种感觉,我的问题的根源来自我代码中的这一行:

# Replace To: field if we're in headers
if ($in_header && $line =~ m/^To: /) {
$line = "To: $email";
}

我不得不承认,我在网上发现了这个代码片段,我对Perl完全不熟悉,以便找到一个可行的解决方案,能够毫无问题地转发到多封电子邮件。任何关于我可以从哪里开始的指示,即使不清楚完整的解决方案,也会非常有帮助。

资源:

https://www.cravingtech.com/how-to-setup-epson-email-print-using-your-own-domain-name.html

#!/usr/bin/perl
use strict;
my $email = 'example@domain.com';
my $sm;
open($sm, "|/usr/sbin/sendmail -t");
my $in_header = 1;
my $in_to = 0;
while (my $line = <STDIN>) {
chomp $line;
# Empty line while in headers means end of headers
if ($in_header && $line eq '') {
$in_header = 0;
}
# Email Header
if ($in_header){
if($line =~ m/^To: /) {
$in_to = 1;
$line = "To: $email";
} elsif($in_to) {
if($line =~ /:/){
$in_to = 0;
}else{
next;
}
}   
}   
print $sm "$linen";
}
close($sm);

经过几个小时的反复试验,这最终成为了我的解决方案。

只是在这里发布这个,以防有人遇到我的小众问题。哈哈。

谢谢。

最新更新