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

Projects
None yet
5 participants
@asanghi
Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

asanghi commented Aug 22, 2012

@josevalim views? thoughts?

@asanghi

This comment has been minimized.

Copy link
Contributor Author

asanghi commented Aug 29, 2012

another gentle nudge /cc @josevalim

@asanghi

This comment has been minimized.

Copy link
Contributor Author

asanghi commented Sep 4, 2012

@josevalim squashed and fixed as per your input.

josevalim added a commit that referenced this pull request Sep 6, 2012

Merge pull request #7397 from asanghi/master
Allow delivery method options to be set per mail instance

@josevalim josevalim merged commit 3c27dcc into rails:master Sep 6, 2012

@saurabhnanda

This comment has been minimized.

Copy link

saurabhnanda commented Oct 4, 2012

Is this patch available in Rails 3.1.1 ?

@asanghi

This comment has been minimized.

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

This comment has been minimized.

Copy link

saurabhnanda commented Oct 4, 2012

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

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 4, 2012

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

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 4, 2012

@lulalala

This comment has been minimized.

Copy link
Contributor

lulalala commented Mar 6, 2013

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

@asanghi

This comment has been minimized.

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
You can’t perform that action at this time.