AFAIK 没有用于处理这种专有格式的模块。相反,将其转换为标准模板系统:
my $template = <<'TEMPLATE';
Good morning, [% name %]!
Today is your first day at work. You have already received your universal login
credentials:
[% ldap_user %]
[% ldap_pass %]
It works for authenticating at the Web proxy, mail system, Jabber and internal
services. Change the password ASAP: <[% ldap_web %]>
--
Yours sincerely, the greeting daemon
TEMPLATE
use Text::Xslate qw();
my $text = Text::Xslate->new(syntax => 'TTerse')->render_string($template, {
name => 'New Bee',
ldap_user => 'nbee',
ldap_pass => 'CON-GLOM-O',
ldap_web => 'http://192.168.0.1:8080/',
});
使用 MIME 工具包创建电子邮件。使用Couriel::Builder可以轻松实现 HTML/multipart/attachments
:
use Courriel::Builder;
my $email = build_email(
subject('Welcome'),
from('no-reply@example.com'),
to('…'),
plain_body($text),
);
最后,使用高级库Email::Sender发送它,它可以为您提供很好的错误检查并允许您轻松切换传输 - 运行本地交付以进行测试。
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP qw();
use Try::Tiny;
try {
sendmail(
$email,
{
transport => Email::Sender::Transport::SMTP->new({
host => 'smtp.example.invalid',
})
}
);
} catch {
warn "sending failed: $_";
};