Send HTML emails with embedded images using ActionMailer

I have a simple ActionMailer class:

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 this comes from the controller:

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

I prefer to keep it simple without templates or such, and it is a web service without submissions.

How can I change it to send HTML emails with embedded images (for example, in img tags)? I need to attach images to the correct mime type and also set the body to the correct mime type, but how?

thank

+3
source share

Source: https://habr.com/ru/post/1770382/


All Articles