Redmine插件开发

Kar*_*amy 3 ruby ruby-on-rails redmine redmine-plugins

我正在尝试为Redmine创建一个消息插件.我对此有几点怀疑

  1. 我怎么能用Redmine插件发送电子邮件?是否可以在插件中创建邮件程序?如果是这样,创建邮件的命令是什么?

  2. 我能够看到这个(call_hook)方法几乎所有的控制器文件.这种方法有什么用?

提前致谢

Kir*_*kov 6

有两种方法可以做到:

  1. 创建新的Mailer并从redmine邮件程序继承它,只需添加新方法即可
  2. 修补redmine邮件程序并添加发送邮件的方法

我在我的插件RedmineCRM中使用了第二个,你可以下载它并检查lib/redmine_contacts/patches/mailer_patch.rb

require 'dispatcher'   

module RedmineContacts
  module Patches    

    module MailerPatch
      module InstanceMethods
        def contacts_note_added(note, parent) 
          redmine_headers 'X-Project' => note.source.project.identifier, 
          'X-Notable-Id' => note.source.id,
          'X-Note-Id' => note.id
          message_id note
          if parent
            recipients (note.source.watcher_recipients + parent.watcher_recipients).uniq
          else
            recipients note.source.watcher_recipients
          end

          subject "[#{note.source.project.name}] - #{parent.name + ' - ' if parent}#{l(:label_note_for)} #{note.source.name}"  

          body :note => note,   
          :note_url => url_for(:controller => 'notes', :action => 'show', :note_id => note.id)
          render_multipart('note_added', body)
        end

        def contacts_issue_connected(issue, contact)
          redmine_headers 'X-Project' => contact.project.identifier, 
          'X-Issue-Id' => issue.id,
          'X-Contact-Id' => contact.id
          message_id contact
          recipients contact.watcher_recipients 
          subject "[#{contact.projects.first.name}] - #{l(:label_issue_for)} #{contact.name}"  

          body :contact => contact,
          :issue => issue,
          :contact_url => url_for(:controller => contact.class.name.pluralize.downcase, :action => 'show', :project_id => contact.project, :id => contact.id),
          :issue_url => url_for(:controller => "issues", :action => "show", :id => issue)
          render_multipart('issue_connected', body)
        end

      end  

      def self.included(receiver)
        receiver.send :include, InstanceMethods
        receiver.class_eval do 
          unloadable   
          self.instance_variable_get("@inheritable_attributes")[:view_paths] << RAILS_ROOT + "/vendor/plugins/redmine_contacts/app/views"
        end  
      end

    end

  end
end

Dispatcher.to_prepare do  

  unless Mailer.included_modules.include?(RedmineContacts::Patches::MailerPatch)
    Mailer.send(:include, RedmineContacts::Patches::MailerPatch)
  end   

end
Run Code Online (Sandbox Code Playgroud)

  • 只需在models文件夹yourplugin_mailer.rb中创建新文件即可.这些不是邮件的插件生成器 (3认同)