【问题标题】:Send html in email with Catalyst and Catalyst::Plugin::Email使用 Catalyst 和 Catalyst::Plugin::Email 在电子邮件中发送 html
【发布时间】:2013-09-06 04:04:11
【问题描述】:

我一直在阅读有关 Catalyst 框架的信息,我正在尝试发送一封包含 HTML 内容的电子邮件,但没有成功。

我尝试使用 Catalyst::Plugin::Email,就像示例 here 一样。电子邮件已发送,但所有内容均以纯文本形式显示。

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,但我不能安装它。

有什么想法吗?

【问题讨论】:

    标签: plugins html-email catalyst


    【解决方案1】:

    我现在可以使用 Catalyst::Plugin::Email 发送 HTML 电子邮件。来自文档:

    “email() 接受与 Email::MIME::Creator 的 create() 相同的参数。”

    查看Email::MIME::Creator,create方法结构为:

    my $single = Email::MIME->create(
        header_str => [ ... ],
        body_str   => '...',
        attributes => { ... },
    );
    
    my $multi = Email::MIME->create(
        header_str => [ ... ],
        parts      => [ ... ],
        attributes => { ... },
    );
    

    "返回属性。哈希键直接对应于方法或修改来自 Email::MIME::Modifier 的消息。允许的键是:内容类型、字符集、名称、格式、边界、编码、处置和文件名。它们将被映射到“$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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-05-23
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多