I know that 2 years have passed since you asked, but I had the same problem and I understood how to send an email with my plugin.
What you should do for a plugin named my_plugin:
1. Create a model that inherits from Mailer.
So, if I need a mailer named MyPluginMailer:
- I create redmine_folder / plugins / my_plugin / app / models / my_plugin_mailer.rb
- I create a class MyPluginMailer that inherits from redmine Mailer
Like:
class MyPluginMailer < Mailer end
2. Create a method to invoke the mailer.
Let's say I'm writing a news plugin for redmine. I want to send an email summarizing the article I submitted so that users cannot poll the plugin every time they want to find out if there is something new.
I create a method in my mailer class:
class MyPluginMailer < Mailer def on_new_article(user_to_warn, article) mail to: user_to_warn.email, subject: "New article:
You can call this method in your Article class in the after_create callback, for example.
3. Create several views for this method.
I have to create 2 different files:
- my_method.html.erb
- my_method.text.erb
otherwise redmine will fail with the exception "pattern not found".
So in my redmine_folder / plugins / my_plugin / app / views / my_plugin_mailer / create
- on_new_article.html.erb
- on_new_article.text.erb
In my on_new_article.html.erb I write something like:
<h1><%= @article.title %></h1> <p><%= @article.summary %></p>
source share