Ruby 添加内联附件时Gmail中缺少电子邮件正文
MyRuby 添加内联附件时Gmail中缺少电子邮件正文,ruby,ruby-on-rails-3,email,ruby-on-rails-3.2,actionmailer,Ruby,Ruby On Rails 3,Email,Ruby On Rails 3.2,Actionmailer,MyUserMailer有一个导出方法,可以将电子邮件发送到某个地址。此电子邮件包含CSV附件和一些内嵌PNG附件。以下是发送电子邮件的操作: # user - the user to send the email to. # csv_files - an array of hashes which represent CSV files to attach to the email. # export_type - the name of the model being expor
UserMailer
有一个导出方法,可以将电子邮件发送到某个地址。此电子邮件包含CSV附件和一些内嵌PNG附件。以下是发送电子邮件的操作:
# user - the user to send the email to.
# csv_files - an array of hashes which represent CSV files to attach to the email.
# export_type - the name of the model being exported (either "customer" or "invoice").
#
# Examples
#
# UserMailer.export_email(current_user, files, "customer")
#
# Returns an email instance.
def export_email(user, csv_files, export_type)
@user = user
from_addy = %|'Exports' <exports@example.com>|
subject = "Your #{export_type} export files."
csv_files.each do |file|
# file[:content] will just be a big CSV string.
opts = { mime_type: 'text/plain', content: file[:content] }
attachments[file[:name]] = opts
end
# export_email_images is an array of hashes of image information defined elsewhere
# in the UserMailer class. These images are used in the email body.
# If I comment out this line and remove the images from my email body
# then everything works fine.
export_email_images.each { |opts| attachments.inline[opts[:name]] = opts }
# I have app/views/user_mailer/customer_export_email view files in both
# .html.erb and .text.erb formats.
mail(to: user.email, subject: subject, from: from_addy,
template_name: "#{export_type}_export_email")
end
#用户-要向其发送电子邮件的用户。
#csv_文件-表示要附加到电子邮件的csv文件的哈希数组。
#导出类型-要导出的模型的名称(“客户”或“发票”)。
#
#例子
#
#导出电子邮件(当前用户,文件,“客户”)
#
#返回电子邮件实例。
def导出电子邮件(用户、csv文件、导出类型)
@用户=用户
from_addy=%|“导出”|
subject=“您的#{export\u type}导出文件。”
csv|U文件。每个do|文件|
#文件[:content]将只是一个大的CSV字符串。
opts={mime_type:'text/plain',内容:file[:content]}
附件[文件[:名称]]=选项
结束
#export_email_images是在别处定义的图像信息散列数组
#在UserMailer类中。这些图像用于电子邮件正文。
#如果我注释掉这一行并从我的邮件正文中删除图像
#然后一切正常。
export_email_images.each{| opts | attachments.inline[opts[:name]]=opts}
#我在这两个文件中都有app/views/user\u mailer/customer\u export\u email视图文件
#.html.erb和.text.erb格式。
邮件(收件人:user.email,主题:subject,发件人:from_addy,
模板名称:“#{export_type}{export_email”)
结束
然而,当我在制作过程中向Gmail发送电子邮件时,尸体不见了:
删除内联附件修复了问题,电子邮件正文正确呈现(显然是SAN内联图像)。这里可能出了什么问题