# Sending email from a plugin

**URL:** https://meta.discourse.org/t/sending-email-from-a-plugin/50064
**Category:** Development
**Created:** [September 13, 2016, 7:58am UTC](https://meta.discourse.org/t/sending-email-from-a-plugin/50064 "2016-09-13T07:58:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 13, 2016, 7:58am UTC](https://meta.discourse.org/t/sending-email-from-a-plugin/50064/1 "2016-09-13T07:58:23Z")

</div>

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:

```ruby
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?

---

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 13, 2016, 12:27pm UTC](https://meta.discourse.org/t/sending-email-from-a-plugin/50064/2 "2016-09-13T12:27:47Z")

</div>

Tried the following inside of `DiscourseEvent` block:

```plaintext
::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:

```plaintext
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?

---

<div class="post-metadata">

### Author: ![kgish](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kgish/32/121131_2.png) [@kgish](https://meta.discourse.org/u/kgish)
#### Post date: [September 13, 2016, 12:31pm UTC](https://meta.discourse.org/t/sending-email-from-a-plugin/50064/3 "2016-09-13T12:31:05Z")

</div>

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

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

```
