Project

General

Profile

Customize E-Mail Subjects

Added by D Brechmann about 12 years ago

Hi .*
I just wanted to customize the E-Mail subjects regarding issues and other topics.
For that I modified the mailer.rb in models/mailer.rb with the following code snippet (note: I added this #{issue.project.parent.name} |):

...
# Builds a Mail::Message object used to email recipients of the added issue.
  #
  # Example:
  #   issue_add(issue) => Mail::Message object
  #   Mailer.issue_add(issue).deliver => sends an email to issue recipients
  def issue_add(issue)
    redmine_headers 'Project' => issue.project.identifier,
                    'Issue-Id' => issue.id,
                    'Issue-Author' => issue.author.login
    redmine_headers 'Issue-Assignee' => issue.assigned_to.login if issue.assigned_to
    message_id issue
    @author = issue.author
    @issue = issue
    @issue_url = url_for(:controller => 'issues', :action => 'show', :id => issue)
    recipients = issue.recipients
    cc = issue.watcher_recipients - recipients
    mail :to => recipients,
      :cc => cc,
      :subject => "[#{issue.project.parent.name} | #{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" 

  end
...

But it seems that it doesnt work :-(
So I checked the modification by modifying the Testmailersubject. After I sent a Testemail I see that the modification wasn't shown.

My System:

Environment:
  Redmine version                          2.1.0.stable
  Ruby version                             1.9.3 (i386-mingw32)
  Rails version                            3.2.8
  Environment                              production
  Database adapter                         Mysql2

It runs on a Win2008Server.

Please note: To get the new mailer.rb running I restarted the IIS and afterwards I triggered a special script to build/configure all modules, but don't know anything exactly about this script but in the past all worked well using it, also implementing most of the used plugins.

So my question is: What did I do wrong or forgot to do?

Thx so far.

Addition: In my vmware (bitnami) it works, so what do I have to do on the win2008 server?
db


Replies (2)

RE: Customize E-Mail Subjects - Added by Agone Bee over 10 years ago

Hi,
i want to do the same,
i change mailer.rb :

<       :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" 
---
>     :subject => "[#{issue.project.parent.name + ' - ' if issue.project.parent}#{issue.project.name}] - #{issue.tracker.name} ##{issue.id} (#{issue.status.name}) #{issue.subject}" 

<     s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " 
---
>     s = "[#{issue.project.parent.name + ' - ' if issue.project.parent}#{issue.project.name}] - #{issue.tracker.name} ##{issue.id} " 

if it helps !

RE: Customize E-Mail Subjects - Added by Rudolph van Niekerk over 7 years ago

I wanted to do add a custom field (named "product") to the email subject for a specific project (in my case, project id: 5).
My (working?) changes are as follows:

In app\models\mailer.rb
(In def issue_add() around Line 53:)

+    s = "[" 
+    s << "#{issue.custom_value_for(CustomField.find_by_name('Product')).value}" if issue.project_id == 5
+    s << "#{issue.project.name}" if issue.project_id != 5
+    s << " - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" 
     mail :to => to_users,
       :cc => cc_users,
-      :subject => "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] (#{issue.status.name}) #{issue.subject}" 
+      :subject => s
   end

(In def issue_edit() around Line 78:)

-    s = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] " 
+    s = "[" 
+    s << "#{issue.custom_value_for(CustomField.find_by_name('Product')).value}" if issue.project_id == 5
+    s << "#{issue.project.name}" if issue.project_id != 5
+    s << " - #{issue.tracker.name} ##{issue.id}] " 
     s << "(#{issue.status.name}) " if journal.new_value_for('status_id')

Then I had to make a small change in issue.rb as well. It seems the custom fields are not readable right after the issue is created, but only once it is saved.

In app\models\issue.rb
(line 116)

    after_destroy :update_parent_attributes
-    after_create :send_notification
+    after_save :send_notification
    # Keep it at the end of after_save callbacks
    after_save :clear_assigned_to_was

Got a lot of help from these forums setting up my redmine.... hope this helps somebody else.

    (1-2/2)