我试图发送一个PDF作为附件的电子邮件,其中包含一些文本在正文。然而,我似乎无法做到这一点,因为电子邮件主体包括附件。我在rails应用程序中有一个非常简单的mailer:
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动作邮件程序可以做到这一点吗?
根据我所看到的,您可以添加附件,但必须在正文中使用明文,或者可以在正文中包含附件,它将使用作为内容类型。
发布于 2019-09-18 06:57:50
对于那些花了4个多小时试图解决这个问题的人来说,我只是安装了sendemail,然后继续我的生活。
https://stackoverflow.com/questions/57985897
复制相似问题