Martin Labuschin
Martin Labuschin

Reputation: 516

Mailer result as String?

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?

Upvotes: 1

Views: 837

Answers (2)

eugen
eugen

Reputation: 9226

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 => "[email protected]"

  def my_email
    mail(:to => "[email protected]", :subject => "Mail Subject")
  end

end

you would do

mail_content = MyMailer.my_email.to_s

Upvotes: 3

Awea
Awea

Reputation: 3173

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

Upvotes: 0

Related Questions