使用 ActionMailer 3 发送 html 附件
我正在尝试发送一封包含单个 HTML 附件的电子邮件。问题是附件 html 出现在电子邮件正文中,而视图显示为附件。与我的预期几乎相反。
我能够正确发送其他类型的附件,但是当尝试发送单个 HTML 附件时,它始终显示而不是“附加”。
class Notifier < ActionMailer::Base
default :from => "[email protected]"
def welcome(email)
attachments['this is an html file.html'] = "<b>yeah this is html!</b>"
mail(:to => email, :subject => "Attempting an attachment")
end
end
我的 app/views/notifier/welcome.html.erb
Hi there! This is <b>html</b> within a view
生成的电子邮件如下所示:(
注意附件 html 实际上显示在电子邮件正文中)
I am trying to send an email which contains a single HTML attachment. The problem is that the attachment html is appearing in the body of the email, and the view is showing up as the attachment. Pretty much the opposite of what I expected.
I am able to send attachments of other types properly, but when trying to send a single attachment that is HTML, it consistently is displayed rather than 'attached'.
class Notifier < ActionMailer::Base
default :from => "[email protected]"
def welcome(email)
attachments['this is an html file.html'] = "<b>yeah this is html!</b>"
mail(:to => email, :subject => "Attempting an attachment")
end
end
And my app/views/notifier/welcome.html.erb
Hi there! This is <b>html</b> within a view
The resulting email looks like this:
(notice the attachment html is actually displayed in the body of the email)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是许多电子邮件客户端的一个功能,如果它们可以内嵌显示附件,那么用户就不必打开单独的程序来查看里面的内容。老实说,虽然它更适合图像。
如果您想发送 html 文件,则需要将其添加到 zip 或其他存档中并发送。
This is a feature of many email clients that if they can display attachments inline they will, so the user doesn't have to open a separate program just to see what's inside. To be honest though it's more meant for images.
If you want to send an html file, you're going to need to add it to a zip or other archive and send that instead.