【问题标题】:Send HTML emails with inline images with ActionMailer使用 ActionMailer 发送带有内嵌图像的 HTML 电子邮件
【发布时间】:2012-07-04 02:20:26
【问题描述】:

我有一个像这样的简单 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

我从控制器中这样使用它:

MyMailer.deliver_mail(mail.from, mail.to, mail.cc, mail.bcc, mail.subject, mail.message)

我更喜欢保持简单,没有模板等,它是一个没有视图的网络服务。

如何更改它以发送带有嵌入图像的 HTML 邮件(我的意思是在 img 标签中)?我需要附加正确的 mime 类型的图像,并使用正确的 mime 类型设置身体,但是如何?

谢谢

【问题讨论】:

    标签: ruby-on-rails


    【解决方案1】:

    如果您使用的是 rails3,这非常容易,如第 2.3.3 节“制作内联附件”in this ruby on rails guide中所述

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2015-07-29
      • 1970-01-01
      • 1970-01-01
      • 2017-02-23
      • 1970-01-01
      • 2012-04-07
      • 1970-01-01
      • 2013-11-11
      • 2011-04-16
      相关资源
      最近更新 更多