Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow delivery method options to be set per mail instance #7397

Merged
merged 1 commit into from
Sep 6, 2012

Conversation

asanghi
Copy link
Contributor

@asanghi asanghi commented Aug 20, 2012

There is a common use case where mail settings are dynamic based on settings saved in database. For example, we could let companies provide us with their SMTP credentials which can be used to send email on their behalf. My particular use case dealt with creating a delivery method which sends SMSes based on company's credentials to company's users.

This PR allows the user to easily set delivery method settings from within the mail instance

class MySmsMailer < ActionMailer::Base
  def send_sms(company,telephone_number,message)
    mail :to => telephone_number, 
         :body => message, 
         :delivery_method => :sms_sender, 
         :delivery_method_options => company.sms_credentials
  end
end

or

class UserMailer < ActionMailer::Base
  def campaign_blast(company,telephone_number,message)
    mail :to => telephone_number, 
         :body => message, 
         :delivery_method_options => {:username => company.smtp_user, 
                                      :password => company.smtp_password}
  end
end

The alternative to doing this would be rather ugly

m = MySmsMailer.send_sms(company,number,message)
m.delivery_method.some_method_that_sets_options_on_sms_sender_instance(company.sms_credentials)
m.deliver

We could try to set delivery options by resetting them on classes but I dont imagine it would be threadsafe to do that!

/cc @josevalim @mikel

@asanghi
Copy link
Contributor Author

asanghi commented Aug 22, 2012

@josevalim views? thoughts?

@asanghi
Copy link
Contributor Author

asanghi commented Aug 29, 2012

another gentle nudge /cc @josevalim

@asanghi
Copy link
Contributor Author

asanghi commented Sep 4, 2012

@josevalim squashed and fixed as per your input.

josevalim pushed a commit that referenced this pull request Sep 6, 2012
Allow delivery method options to be set per mail instance
@josevalim josevalim merged commit 3c27dcc into rails:master Sep 6, 2012
@saurabhnanda
Copy link

Is this patch available in Rails 3.1.1 ?

@asanghi
Copy link
Contributor Author

asanghi commented Oct 4, 2012

No it is not. It is also not available on 3.2.x branch. This has been merged only on Rails 4.0

Rails 3.2.x and below are not accepting new features anymore.

@saurabhnanda
Copy link

Bad. I'm looking for exactly this right now. What would be the best way to
integrate what this patch is doing with the queueing ability provided by
http://code.google.com/p/mail-queue/ ?

On Thu, Oct 4, 2012 at 12:13 PM, Aditya Sanghi notifications@github.comwrote:

No it is not. It is also not available on 3.2.x branch. This has been
merged only on Rails 4.0

Rails 3.2.x and below are not accepting new features anymore.


Reply to this email directly or view it on GitHubhttps://github.com//pull/7397#issuecomment-9132092.

http://www.saurabhnanda.com

@steveklabnik
Copy link
Member

You can fork rails, apply the patch yourself, then use bundler to use your fork.

@steveklabnik
Copy link
Member

@lulalala
Copy link
Contributor

lulalala commented Mar 6, 2013

@asanghi If I use sendmail, will delivery_method_options be referring to sendmail_settings?

@asanghi
Copy link
Contributor Author

asanghi commented Mar 6, 2013

Yes. @lulalala if the delivery_method is set to :sendmail then it refers to sendmail_settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants