使用 MIME::Lite:TT 发送列表

发布于 2024-11-02 12:56:03 字数 976 浏览 0 评论 0原文

我正在尝试通过电子邮件从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紧拥背影 2024-11-09 12:56:03

啊。是的。

如果不知道您的模板是什么样子,就很难提出具体的建议。但是,如果您将其设置为:

$params{ips} = [ qw{ 1.2.3.4  2.3.4.5  3.4.5.6 } ];

并且您的模板有一个看起来像这样的区域:

[% FOREACH address IN ips %]
[% address %]
[% END %]

我认为您的问题将会得到解决。我将把数组分成 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:

$params{ips} = [ qw{ 1.2.3.4  2.3.4.5  3.4.5.6 } ];

and your template had a region that looked like:

[% FOREACH address IN ips %]
[% address %]
[% END %]

your problem would be solved, I think. I leave the splitting up of the array into 20–30 element lists as an exercise. :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文