【问题标题】:ActionMailer sending attachment as the bodyActionMailer 发送附件作为正文
【发布时间】:2020-01-19 00:08:03
【问题描述】:

我正在尝试将 PDF 作为附件发送到正文中包含一些文本的电子邮件。但是,我似乎无法做到这一点,因为电子邮件正文包含附件。我的 Rails 应用程序中有一个非常简单的邮件程序:

class QuickMailer < ApplicationMailer
    def send_mail(smtp_settings, mail_options, attachment=nil)
        unless attachment.nil?
            attachments[attachment[0]] = File.read(attachment[1])
        end
        mail(from: mail_options[:from],
            to: mail_options[:to],
            subject: mail_options[:subject],
            body: "<!DOCTYPE html><body>#{mail_options[:body]}</body>",
            content_type: "text/html"
            )
    end
end

如果我删除这一行:

content_type: "text/html"

然后它将附件作为附件发送,但正文包含需要为 HTML 的纯文本。我似乎无法同时完成两者。

我做错了什么?我看到其他人问过这个问题,但似乎没有任何答案。 Rails 动作邮件程序可以做到这一点吗?

据我所知您可以添加附件,但在正文中强制使用纯文本,或者您可以在正文中包含附件,它将使用 HTML 作为内容类型

【问题讨论】:

    标签: ruby-on-rails actionmailer


    【解决方案1】:

    对于其他花了 4 多个小时试图解决这个问题的人,我刚刚安装了 sendemail 并继续我的生活。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-27
      • 1970-01-01
      • 2013-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多