使用 ActionMailer 发送带有内嵌图像的 HTML 电子邮件 [英] Send HTML emails with inline images with ActionMailer
问题描述
我有一个简单的 ActionMailer 类,如下所示:
I have a simple ActionMailer class like this:
class MyMailer < ActionMailer::Base
def mail(from, to, cc, bcc, subject, message, sent_at = Time.now)
@subject = subject
@recipients = to
@from = from
@cc = cc
@bcc = bcc
@sent_on = sent_at
@body["message"] = message
@headers = {}
end
end
我从控制器上是这样的:
And I ue it like this from a controller:
MyMailer.deliver_mail(mail.from, mail.to, mail.cc, mail.bcc, mail.subject, mail.message)
我更喜欢保持简单,没有模板等,它是一个没有视图的网络服务.
I prefer to keep it simple with no templates or such, and it is a webservice with no views.
如何更改它以便能够发送带有嵌入图像的 HTML 邮件(我的意思是在 img 标签中)?我需要附加正确的 mime 类型的图像,并使用正确的 mime 类型设置主体,但如何?
How do I change it to be able to send HTML mails with embedded images (in img tags i mean)? I need to attach the images woth the correct mime-type and also set the body with the correct mime-type, but how?
谢谢
推荐答案
你见过:http://edgeguides.rubyonrails.org/action_mailer_basics.html#sending-emails-带附件对于 rails3
have you seen: http://edgeguides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments for rails3
和:
http://guides.rubyonrails.org/action_mailer_basics.html#发送带有附件的电子邮件
对于 rails2
这篇关于使用 ActionMailer 发送带有内嵌图像的 HTML 电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!