我一直在阅读有关Catalyst框架的文章,我试图发送一封包含HTML内容的电子邮件,但没有成功。
我尝试使用Catalyst::Plugin::Email,就像这里的例子一样。电子邮件已发送,但所有内容都以纯文本显示。
sub send_email : Local {
my ($self, $c) = @_;
$c->email(
header => [
To => 'me@localhost',
Subject => 'A TT Email',
],
body => $c->view('Web')->render($c, 'email.tt', {
additional_template_paths => [ $c->config->{root} . '/email_templates'],
email_tmpl_param1 => 'foo'
}
),
);
# Redirect or display a message
}
我也读过Catalyst::View::Email::Template,但我没有安装它。
知道吗?
我现在可以使用Catalyst::Plugin::Email发送HTML电子邮件。来自文件:
"email()接受与email::MIME::Creator的create()相同的参数。"
查看电子邮件::MIME::Creator,创建方法结构为:
my $single = Email::MIME->create(
header_str => [ ... ],
body_str => '...',
attributes => { ... },
);
my $multi = Email::MIME->create(
header_str => [ ... ],
parts => [ ... ],
attributes => { ... },
);
返回属性。哈希键直接对应于方法或修改来自电子邮件::MIME::Modifier的消息。允许的键有:content_type、字符集、名称、格式、边界、编码、处置和文件名。它们将映射到"$attr_set"以进行消息修改。
这是它正在工作的代码:
sub send_email : Local {
my ($self, $c) = @_;
$c->email(
header => [
To => 'me@localhost',
Subject => 'A TT Email',
],
body => $c->view('Web')->render($c, 'email.tt', {
additional_template_paths => [ $c->config->{root} . '/email_templates'],
email_tmpl_param1 => 'foo'
}
),
attributes => {
content_type => 'text/html',
charset => 'utf-8'
},
);
# Redirect or display a message
}