Created
August 3, 2015 20:44
-
-
Save michelson/1658ad3c79a888f55250 to your computer and use it in GitHub Desktop.
mail catcher for rails env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if Rails.env.test? | |
class MailCatcher | |
def self.create(opts) | |
File.open("#{Rails.root}/tmp/mailcatcher/mail-#{Time.now.to_i}.html", 'w') do |f| | |
f.write(opts[:body].raw_source) | |
end | |
end | |
end | |
module ActionMailerCatcher | |
module InstanceMethods | |
def send_with_mail_catch!(opts={}) | |
send_without_mail_catch!(opts) | |
logger.info "STORING MAIL IN MONGO!" | |
MailCatcher.create( | |
:from=> @_message.from , | |
:to=> @_message.to, | |
:body=> @_message.body , | |
:content_type=> @_message.content_type , | |
:subject=> @_message.subject, | |
:reply_to=> @_message.reply_to | |
) if MailCatcher | |
end | |
end | |
def self.included(receiver) | |
receiver.send :include, InstanceMethods | |
receiver.class_eval do | |
alias_method_chain :send!, :mail_catch | |
end | |
end | |
end | |
BaseMailer.send :include, ActionMailerCatcher | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
create file in:
config/initializers
create folder in tmp:
tmp/mailcatcher