1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 class Mailer < ActionMailer::Base
19 helper ApplicationHelper
21 helper CustomFieldsHelper
23 def account_information(user, password)
24 set_language_if_valid user.language
26 from Setting.mail_from
27 subject l(:mail_subject_register)
28 body :user => user, :password => password
32 set_language_if_valid(Setting.default_language)
33 # Sends to all project members
34 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
35 # Sends to author and assignee (even if they turned off mail notification)
36 @recipients << issue.author.mail if issue.author
37 @recipients << issue.assigned_to.mail if issue.assigned_to
40 @from = Setting.mail_from
41 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
42 @body['issue'] = issue
45 def issue_edit(journal)
46 set_language_if_valid(Setting.default_language)
47 # Sends to all project members
48 issue = journal.journalized
49 @recipients = issue.project.members.collect { |m| m.user.mail if m.user.mail_notification }.compact
50 # Sends to author and assignee (even if they turned off mail notification)
51 @recipients << issue.author.mail if issue.author
52 @recipients << issue.assigned_to.mail if issue.assigned_to
56 @cc = issue.watcher_recipients - @recipients
57 @from = Setting.mail_from
58 @subject = "[#{issue.project.name} - #{issue.tracker.name} ##{issue.id}] #{issue.status.name} - #{issue.subject}"
59 @body['issue'] = issue
60 @body['journal']= journal
63 def document_added(document)
64 set_language_if_valid(Setting.default_language)
65 @recipients = document.project.users.collect { |u| u.mail if u.mail_notification }.compact
66 @from = Setting.mail_from
67 @subject = "[#{document.project.name}] #{l(:label_document_new)}: #{document.title}"
68 @body['document'] = document
71 def attachments_added(attachments)
72 set_language_if_valid(Setting.default_language)
73 container = attachments.first.container
76 case container.class.name
78 url = {:only_path => false, :host => Setting.host_name, :controller => 'projects', :action => 'list_files', :id => container.project_id}
79 added_to = "#{l(:label_version)}: #{container.name}"
81 url = {:only_path => false, :host => Setting.host_name, :controller => 'documents', :action => 'show', :id => container.id}
82 added_to = "#{l(:label_document)}: #{container.title}"
84 @recipients = container.project.users.collect { |u| u.mail if u.mail_notification }.compact
85 @from = Setting.mail_from
86 @subject = "[#{container.project.name}] #{l(:label_attachment_new)}"
87 @body['attachments'] = attachments
89 @body['added_to'] = added_to
93 set_language_if_valid(Setting.default_language)
94 @recipients = news.project.users.collect { |u| u.mail if u.mail_notification }.compact
95 @from = Setting.mail_from
96 @subject = "[#{news.project.name}] #{l(:label_news)}: #{news.title}"
100 def lost_password(token)
101 set_language_if_valid(token.user.language)
102 @recipients = token.user.mail
103 @from = Setting.mail_from
104 @subject = l(:mail_subject_lost_password)
105 @body['token'] = token
109 set_language_if_valid(token.user.language)
110 @recipients = token.user.mail
111 @from = Setting.mail_from
112 @subject = l(:mail_subject_register)
113 @body['token'] = token
116 def message_posted(message, recipients)
117 set_language_if_valid(Setting.default_language)
118 @recipients = recipients
119 @from = Setting.mail_from
120 @subject = "[#{message.board.project.name} - #{message.board.name}] #{message.subject}"
121 @body['message'] = message
125 set_language_if_valid(user.language)
126 @recipients = user.mail
127 @from = Setting.mail_from