2

My scenario an issue change status in "closed" and redmine must send an email to an email address

My constraint:

  1. issue assignee could not change
  2. email must be configurable by user administration
  3. only one email for issue

I'm currently using Redmine 2.4.3 final and because I'm not able to find a setting or existing plugin to get this done, I'm writting down a plugin, here my code:

require 'mailer'

module IssueAssignToPlugin
  class Hooks < Redmine::Hook::ViewListener
    def controller_issues_edit_before_save(context={})
        configuration = Setting.plugin_helloworldredmineplugin
        if  !configuration.nil? && configuration['enabled'] && !configuration['user_id'].blank? && !configuration['status_id'].blank?
            issue = context[:issue]
            status = IssueStatus.find(configuration['status_id'])
            user = User.find(configuration['user_id'])
            if !user.nil? && !issue.watched_by?(user)
                if issue.status == status
                    #issue.add_watcher(user)
                    #journal = issue.journals.last
                    #journal = Journal.new(:journalized => issue, :user => user, :created_on => Time.now)
                    #journal.details << JournalDetail.new(:property => 'relation', :prop_key => 'label_relates_to', :value => 2)
                    #Mailer.deliver_issue_edit(journal)
                    #mail(to: user.mail, cc: user.mail, bbc: user.mail)
                    #Mailer.deliver_mail(mail)
#
#Your code goes here!
#
                end
            end
        end
        return ''
    end
    alias_method :controller_issues_bulk_edit_before_save, :controller_issues_edit_before_save
    alias_method :controller_issues_new_before_save, :controller_issues_edit_before_save
  end
end

As you can see I've tried many ways, but without luck.

Could someone please help me? My problem is "just" send an Email having only user.mail and using Redmine "settings"

Vokail
  • 630
  • 8
  • 27
  • I think 1. when issue status is changed `Mailer.deliver_issue_edit(journal)` is triggered 2. you should check if your user is in [`jornal.notified_users`](https://github.com/redmine/redmine/blob/2.4-stable/app/models/journal.rb#L123) (I think required user is not there) 3. you should find a way how to add your user to the method result – gotva Mar 06 '14 at 06:55
  • yes, with journal works fine, but how to checj notified_users ? I'm a nood on ruby, rails and Redmine – Vokail Mar 07 '14 at 14:22
  • There are several ways. for example add code `raise jornal.notified_users` - this will raise an exception where you can see who will be notified. I think the list does not have your user and you need to patch it. – gotva Mar 08 '14 at 15:56
  • I'm back on this issue, because I didn't find a viable solution. If someone have a concrete example to just send an email inside a Redmine plugin, please let me know – Vokail Mar 19 '14 at 15:57
  • 1
    maybe [this](https://github.com/guilhermenoronha/redmine_send_mails/blob/master/lib/mailer/mailer_patch.rb) can help you. Plugin patches mailer and I believe sends emails. PS haven't checked by myself – gotva Mar 20 '14 at 09:50

0 Answers0