perl - 使用 Perl 问题将电子邮件转发到 Epson 打印机“电子邮件打印”
问题描述
我目前正在使用 Cpanel 设置电子邮件转发,该电子邮件转发通过 CPanel 电子邮件转发“Pipe to Program”中的功能进行。在这个 perl 脚本中,我抓取标题并将它们替换为 Epson 电子邮件打印地址,因为 Epson 打印机不喜欢直接转发。但是,我遇到的问题是一次发送给多个用户会导致错误,并且它不喜欢超过 1 个收件人。
我的代码如下:
#!/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 "$line\n";
}
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 "$line\n";
}
close($sm);
经过数小时的反复试验,这最终成为了我的解决方案。
只是在这里发布这个,以防有人遇到我的小众问题哈哈。
谢谢。
推荐阅读
- amazon-web-services - 通过 cloudformation 使用 aws `cdk synth` 输出
- javascript - 反转 L:CRS 的 Y 轴。Vue2-Leaflet 上的简单地图
- django - Ngnix Django 502 错误网关
- authentication - 来自非浏览器客户端的 SAML(或其他)身份验证流程
- linear-programming - 如何用语言编写以下目标函数的语法
- c++ - 霍夫圆检测确定性
- xaml - 将列表中 itemselected 的 id 传递给按钮 xamarin
- javascript - 如何在谷歌日历api的事件对象中设置开始和结束时间
- powerbi - 具有多个特定于报告组的聚合的星型模式:好或坏
- python - 如何将我的 csv 文件连接到不同的列中?