Ruby on rails ActionMailer将附件作为正文发送
我试图发送一个PDF作为附件的电子邮件,其中包含一些正文文本。然而,我似乎无法做到这一点,因为电子邮件正文包含附件。我的rails应用程序中有一个非常简单的邮件程序:Ruby on rails ActionMailer将附件作为正文发送,ruby-on-rails,actionmailer,Ruby On Rails,Actionmailer,我试图发送一个PDF作为附件的电子邮件,其中包含一些正文文本。然而,我似乎无法做到这一点,因为电子邮件正文包含附件。我的rails应用程序中有一个非常简单的邮件程序: class QuickMailer < ApplicationMailer def send_mail(smtp_settings, mail_options, attachment=nil) unless attachment.nil? attachments[attachm
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
classquickmailer
如果我删除此行:
content\u类型:“text/html”
然后它将附件作为附件发送,但正文包含需要为HTML的纯文本。我似乎不能同时做到这两件事
我做错了什么?我见过其他人问这个问题,但似乎没有任何答案。rails action mailer是否可以实现这一点
从我所看到的你可以添加一个附件,但必须在正文中使用纯文本,或者你可以在正文中包含附件,它将使用HTML作为内容类型对于任何花了4个多小时试图弄明白这一点的人,我只是安装了
发送电子邮件
,然后继续我的生活