# Dynamically changing ActionMailer::Base.delivery\_method

**URL:** <https://www.ruby-forum.com/t/dynamically-changing-actionmailer-base-delivery-method/194697>\
**Category:** Rails\
**Created:** [September 9, 2010, 7:50am UTC](https://www.ruby-forum.com/t/dynamically-changing-actionmailer-base-delivery-method/194697 "2010-09-09T07:50:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [September 9, 2010, 7:50am UTC](https://www.ruby-forum.com/t/dynamically-changing-actionmailer-base-delivery-method/194697/1 "2010-09-09T07:50:39Z")

</div>

Hi all,

I need some of my emails to go out using “smtp” and some others using  
“sendmail” . Is there a clean way to switch between these two deliver  
methods depending upon the mailer method?

Thanks!

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [September 9, 2010, 1:19pm UTC](https://www.ruby-forum.com/t/dynamically-changing-actionmailer-base-delivery-method/194697/2 "2010-09-09T13:19:04Z")

</div>

maybe with a rake task for the send mail one, running with deamon but it  
will have to load your app and change the config, i think it will get  
ugly.

---

<div class="post-metadata">

**Author:** ![ram](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@ram](https://www.ruby-forum.com/u/ram)\
**Post date:** [September 9, 2010, 1:40pm UTC](https://www.ruby-forum.com/t/dynamically-changing-actionmailer-base-delivery-method/194697/3 "2010-09-09T13:40:44Z")

</div>

On Sep 9, 6:47 am, Ram [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi all,
> 
> I need some of my emails to go out using “smtp” and some others using  
> “sendmail” . Is there a clean way to switch between these two deliver  
> methods depending upon the mailer method?

I think (but do test this!) that you could do something like

class SmtpMailer \< AM::Base  
self.delivery\_method = :smtp  
end

class SendmailMailer \< AM::Base  
self.delivery\_method = :sendmail  
end

and then derive mailers from those two classes as appropriate. If you  
have identical mail that needs to be delivered via either of those two  
mechanisms then it might be a bit more complicated.

Fred
