当我使用ActionMailer发送带附件的邮件时,电子邮件正文丢失了

时间:2010-08-03 06:39:43

标签: ruby-on-rails ruby actionmailer

视图中的内容未显示。仅发送附件。帮助将不胜感激!

def send
 @subject = "Status of PIS App"
 @recipients = "ssg@gmail.com"
 @from = APP_CONFIG[:email]
 @sent_on = Time.now
 #@content_type = "text/html"
 content_type = "multipart/alternative"

 attachment :filename => "Report.html",:content_type => "text/html",
  :body => File.read("/home/shreyas/repos/mysorepoc/app/models/new1.html")
end

1 个答案:

答案 0 :(得分:1)

使用附件时,您需要单独指定文本部分:

def send
  @subject = "Status of PIS App"
  @recipients = "ssg@gmail.com"
  @from = APP_CONFIG[:email]
  @sent_on = Time.now
  #@content_type = "text/html"
  content_type = "multipart/mixed"

  part :content_type => "text/plain", :body => "contents of body"

  attachment :filename => "Report.html",:content_type => "text/html", :body => File.read("/home/shreyas/repos/mysorepoc/app/models/new1.html")
end

您可能希望将邮件作为multipart / mixed发送,而不是作为multipart / alternative(除非附件确实是文本部分的替代表示)。