title: Override mail function in rails ActionMailer
body: <p>I use this class for Action Mailer:</p>
  
  <pre><code>class UserMailer &lt; ActionMailer::Base
  
    default from: "something@example.com",
            reply_to: 'whatever@example.com'
  
    def mail_method
      mail(to: 'email@example.com', subject: "SUBJECT")
    end
  end
  </code></pre>
  
  <p>So like this I got many classes and methods which send emails like this from smtp delivery method.</p>
  
  <p>But now I want to perform_deliveries , i.e. send emails only on production environment not in development or test environment.</p>
  
  <p>So for that I want to use my email only, which is why I need to override mail method.</p>
  
  <p>Things I have tried.</p>
  
  <p>-> Making a function to return email, where function name is get_right_email</p>
  
  <pre><code>class UserMailer &lt; ActionMailer::Base
  
    default from: "something@example.com",
            reply_to: 'whatever@example.com'
  
    def mail_method
      mail(to: get_right_email('email@example.com'), subject: "SUBJECT")
    end
  end
  </code></pre>
  
  <p>And definition of get_right_email is as follows:</p>
  
  <pre><code>def get_right_email(email)
    if(Rails.env=='production')
      return email
    else 
      return 'myPersonalEmail@example.com'
    end
  end
  </code></pre>
  
  <p>It would need some refactoring but it is still manageable. Will take a few hours and I can do, but is there a quicker way where I can just override mail function.</p>