2

In my plugin for Discourse I am trying to send an email to a user.

This works just fine if I hardcode my own API functionality to do so, however in an effort to make this public I was trying to use the built in emailing. I cannot however get an email to send.

I have tried:

def self.send_user_email(address)
  message = Mail::Message.new(from: "from@fromEmail.com", to: address, body: "hello")
  Email::Sender.new(message, :admin_login).send # I used admin_login as according to the spec it should send even if email is disabled. 
end

When I do this however I am getting an error:

NoMethodError - undefined method `deliver_now' for #<Mail::Message:0x007fa1bf157300>
Did you mean?  deliver:
  mail (2.6.6) lib/mail/message.rb:1379:in `method_missing'

So if I go and update line 184 of sender.rb in Discourse to use #deliver instead of #deliver_now, I am able to get it to kinda try to send an email on my development environment.

Drenmi
  • 8,492
  • 4
  • 42
  • 51
basic
  • 3,348
  • 3
  • 21
  • 36

1 Answers1

0

Rails 4.2 deprecated deliver / deliver! in favor of deliver_now / deliver_now!. (Pull Request)
http://guides.rubyonrails.org/4_2_release_notes.html#action-mailer-deprecations

Rails 5.0 removed deprecated deliver and deliver! methods. (commit) http://guides.rubyonrails.org/5_0_release_notes.html#action-mailer-removals


This is the reason why you are getting the error. Rails applications >= 5.0 will have this error until the source code you referred to is updated.

Arturo Herrero
  • 12,772
  • 11
  • 42
  • 73