当电子邮件带有附件时,Rails 2.3.11 ActionMailer 不会呈现 html
我正在使用 Rails 2.3.11。我使用以下方法创建了一个 UserMailer:
def rsvp_created(user, rsvp, pdf_file)
setup_email(user)
content_type "multipart/mixed"
@subject << "Your RSVP for #{rsvp.ticket.holiday.title}"
@body[:rsvp] = rsvp
attachment :content_type => 'application/pdf',
:body => File.read(pdf_file),
:filename => "#{rsvp.confirmation_number}.pdf"
end
def rsvp_cancelled(user, rsvp)
setup_email(user)
content_type "text/html"
@subject << "Cancelled RSVP for #{rsvp.ticket.holiday.title}"
@body[:rsvp] = rsvp
@body[:holiday_url] = APP_CONFIG['site_url'] + holiday_path(rsvp.ticket.holiday)
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = APP_CONFIG['admin_email']
@subject = "[#{APP_CONFIG['site_name']}] "
@sent_on = Time.now
@body[:user] = user
end
rsvp_cancelled 工作正常并正确发送电子邮件。但带有附件的 rsvp_created 电子邮件无法正常工作。它发送带有附件的电子邮件,但不呈现任何文本。有人以前遇到过这个问题或者知道我该如何解决它吗?
谢谢
I am using Rails 2.3.11. I created a UserMailer with following methods:
def rsvp_created(user, rsvp, pdf_file)
setup_email(user)
content_type "multipart/mixed"
@subject << "Your RSVP for #{rsvp.ticket.holiday.title}"
@body[:rsvp] = rsvp
attachment :content_type => 'application/pdf',
:body => File.read(pdf_file),
:filename => "#{rsvp.confirmation_number}.pdf"
end
def rsvp_cancelled(user, rsvp)
setup_email(user)
content_type "text/html"
@subject << "Cancelled RSVP for #{rsvp.ticket.holiday.title}"
@body[:rsvp] = rsvp
@body[:holiday_url] = APP_CONFIG['site_url'] + holiday_path(rsvp.ticket.holiday)
end
protected
def setup_email(user)
@recipients = "#{user.email}"
@from = APP_CONFIG['admin_email']
@subject = "[#{APP_CONFIG['site_name']}] "
@sent_on = Time.now
@body[:user] = user
end
The rsvp_cancelled works fine and sends email properly. But the rsvp_created email, which has an attachment, doesn't work properly. It sends the email with the attached file but doesn't render any text. Any one faced this issue before or know how I can resolve it?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Rails 2.x,由于某种原因,您需要定义 HTML 出现的所有部分。
值得庆幸的是,Rails 3.x 中的情况似乎并非如此。
With Rails 2.x, for some reason or the other you need to define all the parts for the HTML to appear.
Thankfully it appears this is not the case in Rails 3.x.
我试图做同样的事情,但按照上面道格拉斯的回答,不断收到损坏的 pdf 附件。我终于能够通过以二进制模式读取pdf文件来解决这个问题:
I was trying to do the same sort of thing, but following Douglas' answer above, kept getting corrupted pdf attachments. I was finally able to resolve the issue by reading the pdf file in binary mode:
我能够让我的答案与道格拉斯的答案一起工作,但也能够让它在一行中工作。我使用的是模板,但这也可以通过用“rsvp”替换 render_message 方法来实现。
I was able to get mine working with Douglas' answer but was also able to get it working in one line. I was using a template but this also works by substituting "rsvp" for the render_message method.