使用 MIME::Lite:TT 发送列表
我正在尝试通过电子邮件从 Postgres 查询发送 IP 列表。
我找到了 MIME::Lite::TT,现在已经安装并运行了。我想在每封电子邮件中以换行分隔列表的形式传递 20-30 个 IP。我可以通过为我需要发送的每封电子邮件生成一个新的 .txt 模板来做到这一点,但这似乎效率低下。我在cpan上找到了Template,我认为@list部分是我需要的,但我不知道如何实现它。
传递 $params{ips} = "1.2.3.4\n2.3.4.5\n3.4.5.6\n" 也不起作用。
谢谢你的想法。
此代码成功发送单个 IP:
#!/usr/bin/perl -w
use MIME::Lite::TT;
# SendTo email id
my $email = '[email protected]';
my %params;
$params{ips} = "1.2.3.4";
# create a new MIME Lite based email
my $msg = MIME::Lite::TT->new
(
Subject => "HTML email test",
From => '[email protected]',
To => $email,
Type => 'text/html',
Template => 'test.txt',
TmplParams => \%params
);
$msg->send();
I'm trying to send a list of IPs from a Postgres query via e-mail.
I found MIME::Lite::TT and now have that installed and working. I'd like to pass 20-30 IPs out in each e-mail in a line feed delimited list. I could do it by generating a new .txt template for each e-mail I need to send, but that seems inefficient. I found Template on cpan, and I think the @list part is what I need, but I don't have any idea how to implement it.
Passing $params{ips} = "1.2.3.4\n2.3.4.5\n3.4.5.6\n" didn't work either.
Thanks for your thoughts.
This code sends a single IP successfully:
#!/usr/bin/perl -w
use MIME::Lite::TT;
# SendTo email id
my $email = '[email protected]';
my %params;
$params{ips} = "1.2.3.4";
# create a new MIME Lite based email
my $msg = MIME::Lite::TT->new
(
Subject => "HTML email test",
From => '[email protected]',
To => $email,
Type => 'text/html',
Template => 'test.txt',
TmplParams => \%params
);
$msg->send();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
啊。是的。
如果不知道您的模板是什么样子,就很难提出具体的建议。但是,如果您将其设置为:
并且您的模板有一个看起来像这样的区域:
我认为您的问题将会得到解决。我将把数组分成 20-30 个元素列表作为练习。 :)
Ah. Yeah.
Without knowing what your template looks like, it's difficult to come up with a specific suggestion. However, if you set this up as:
and your template had a region that looked like:
your problem would be solved, I think. I leave the splitting up of the array into 20–30 element lists as an exercise. :)