1

In our custom sales app our users are able to send emails based on text partials they choose. We need to record the sent mails in an activity model. How do I get the mailer result as a string in order to save it?

Martin Labuschin
  • 516
  • 4
  • 16

2 Answers2

3

Instead of calling the deliver method to send the mail, you can capture the email message by calling to_s. For example, if you have a mailer:

class MyMailer < ActionMailer::Base

  default :from => "sender@me.com"

  def my_email
    mail(:to => "destination@you.com", :subject => "Mail Subject")
  end

end

you would do

mail_content = MyMailer.my_email.to_s
eugen
  • 8,916
  • 11
  • 57
  • 65
0

May be you can using a mail observer like in the following example :

class MailObserver
    def self.delivered_email(message)
         test = Activty.create do |activity|
             # etc.
         end
    end
end 

Find here

Community
  • 1
  • 1
Awea
  • 3,163
  • 8
  • 40
  • 59