[英]Send HTML emails with inline images with ActionMailer
I have a simple ActionMailer class like this: 我有一个简单的ActionMailer类,如下所示:
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. 我更喜欢保持简单,没有模板等,它是一个没有视图的Web服务。
How do I change it to be able to send HTML mails with embedded images (in img tags i mean)? 如何更改它以便能够发送带有嵌入图像的HTML邮件(我的意思是img标签)? I need to attach the images woth the correct mime-type and also set the body with the correct mime-type, but how? 我需要附加正确的mime类型的图像,并设置正确的mime类型的身体,但如何?
Thank you 谢谢
如果你使用的是rails3,那就很容易了,正如这篇ruby on rails指南第2.3.3节“制作内联附件”所述
have you seen: http://edgeguides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments for rails3 你见过: http ://edgeguides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments for rails3
and: 和:
http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments
for rails2 对于rails2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.