Sending email from a plugin


(Kgish) #1

I’d like to send out a notification email whenever a given topic with a certain category is closed. So far I I have the following event handler defined:

DiscourseEvent.on(:topic_status_updated) do |topic_id, status, enabled|
  # Send email notification when status == 'closed'
end

What is the proper way to do this? Do I need to define my own ApplicationMailer in my plugin apps/mailer sub-directory or can I just make a call through Discourse?


(Kgish) #2

Tried the following inside of DiscourseEvent block:

::DiscourseMyPlugin::MyPluginMailer.status_changed(topic, status).deliver

but get a method_missing error.

If I try calling it from outside of DiscourseEvent block, e.g. in a controller like this:

DiscourseMyPlugin::MyPluginMailer.status_changed(topic, status).deliver

It works.

Seems to be something to do with scopes and visibility, what might I be doing wrong?


(Kgish) #3

Yes, I load the mailer at the top of the file like this:

load File.expand_path('../mailers/myplugin_mailer.rb', __FILE__)