W
W
WordPress WooCommerce2017-04-14 17:57:31
Ruby on Rails
WordPress WooCommerce, 2017-04-14 17:57:31

How to send your email when creating a task in Redmine?

Please help me figure out how mail works in conjunction with the task creation hook in Redmine projects.
I understand the hook itself here https://github.com/redmine/redmine/blob/1cd985dd6b...
Next, you need something like this:

module MyMailSender
  class Hooks < Redmine::Hook::ViewListener
    def controller_issues_new_after_save(context={ })
      # как то надо отправить почту на адрес [email protected]
    end
  end
end

it should be located in the file www/redmine/plugins/myaweplugin/lib/hooks.rb
Then I got straight into the intrusion on the question of what and how do I send mail?
For example, in php this is done in 1 line:
mail('[email protected]', 'My Subject', 'My message');
WP has a wrapper for this method with a number of goodies: wp_mail() - but the task is also solved in 1 line.
I rummaged through the whole Google, I found the darkness of methods, but none of them looks understandable for embedding into this logic. And some of the solutions come down to the fact that you need to write a whole bunch of code with the creation of classes, etc. I feel that I don’t understand something in RoR || Redmine.
I would be grateful for a hint in the right direction or a link to examples ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem Gladyshev, 2017-04-17
@maxxannik

redmine has a method that looks similar to the one in php. Mailer class, method mail.
You can call something like this, but first you need to define the layout
, but this is not a nice way
to patch mailer.rb and add your send method to it, which will collect all the necessary data for sending and call the mail method.
To make it clearer for you, see how, for example, notifications are sent for changes in tasks.
First, the deliver_issue_edit method is called, all users are selected for sending, and for each of them the issue_edit method is called, which collects a letter for sending, the prepared letter is sent by the deliver method
It turned out a little chaotically, but the essence reflects

R
Roman Mirilaczvili, 2017-04-15
@2ord

You can send either using Redmine-specific means (read the documentation) or by inheriting from ActionMailer::Base.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question