I am writing a Redmine plugin. I already have the model, view and controller in place. Whenever someone creates, updates or deletes my model I want to send an email to people in a certain group. (Similar to emails sent out by Redmine when someone creates or updates an Issue) Could someone please let me know what would be the best way to go about it? Thanks!
I know it's been 2 years since you asked but I had the same issue and I figured out how to send an email with my plugin.
What you have to do for a plugin named my_plugin is :
So if I want a mailer named MyPluginMailer :
Like that:
class MyPluginMailer < Mailer
end
Say I am writing a news plugin for redmine. I want to send an email which summarizes the article I submitted so that users do not have to poll the plugin each time they want to know 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: #{article.title}"
@article = article #So that @article will be available in the views.
end
end
You can call this method in your Article class in an after_create callback for example.
I have to create 2 differents files :
or else redmine is going to crash with a "template not found" exception.
So in my redmine_folder/plugins/my_plugin/app/views/my_plugin_mailer/ I create
In my on_new_article.html.erb I write something like :
<h1><%= @article.title %></h1>
<p><%= @article.summary %></p>