【问题标题】:Redmine plugin developmentRedmine插件开发
【发布时间】:2012-04-24 13:29:15
【问题描述】:

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

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

  2. 我几乎可以看到 this(call_hook) 方法 控制器文件。这个方法有什么用?

提前致谢

【问题讨论】:

    标签: ruby-on-rails ruby redmine redmine-plugins


    【解决方案1】:

    有两种方法:

    1. 创建新的 Mailer 并从 redmine mailer 继承它,然后根据需要添加新方法
    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
    

    【讨论】:

    • 我尝试使用以下命令创建邮件程序,但它无法正常工作“ruby 脚本/生成 redmine_plugin_mailer 通信通知程序”,我收到以下错误“找不到 'redmine_plugin_mailer' 生成器”
    • 只需在模型文件夹 yourplugin_mailer.rb 中创建新文件。这些不是邮件程序的插件生成器
    猜你喜欢
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-31
    • 2013-06-07
    • 1970-01-01
    相关资源
    最近更新 更多