简体   繁体   English

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

[英]The email body is missing when I send mails with attachements using ActionMailer

The content in the view is not being displayed. 视图中的内容未显示。 Only the attachment is being sent. 仅附件正在发送。 Help would be appreciated! 帮助将不胜感激!

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

When using attachments, you need to specify the text part separately: 使用附件时,需要单独指定文本部分:

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

And you probably want to send the mail as a multipart/mixed, not as multipart/alternative (unless the attachment really is an alternative representation of the text part). 而且您可能希望以多部分/混合形式而不是多部分/替代形式发送邮件(除非附件确实是文本部分的替代表示)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM