2

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

但是,当我在生产环境中将电子邮件发送到 Gmail 时,缺少正文:

Gmail 缺少电子邮件正文

删除内联附件解决了问题,并且电子邮件正文正确呈现(显然没有内联图像)。这里有什么问题?

4

0 回答 0