1 class Notifier < ActionMailer::Base
2 default :from => EMAIL_FROM,
3 :return_path => EMAIL_RETURN_PATH,
4 :auto_submitted => "auto-generated"
7 def signup_confirm(user, token)
8 with_recipient_locale user do
9 # If we are passed an email address verification token, create
10 # the confirumation URL for account activation.
12 # Otherwise the email has already been verified e.g. through
13 # a trusted openID provider and the account is active and a
14 # confirmation URL is not needed.
16 @url = url_for(:host => SERVER_URL,
17 :controller => "user", :action => "confirm",
18 :display_name => user.display_name,
19 :confirm_string => token.token)
22 mail :to => user.email,
23 :subject => I18n.t('notifier.signup_confirm.subject')
27 def email_confirm(user, token)
28 with_recipient_locale user do
29 @address = user.new_email
30 @url = url_for(:host => SERVER_URL,
31 :controller => "user", :action => "confirm_email",
32 :confirm_string => token.token)
34 mail :to => user.new_email,
35 :subject => I18n.t('notifier.email_confirm.subject')
39 def lost_password(user, token)
40 with_recipient_locale user do
41 @url = url_for(:host => SERVER_URL,
42 :controller => "user", :action => "reset_password",
43 :token => token.token)
45 mail :to => user.email,
46 :subject => I18n.t('notifier.lost_password.subject')
50 def gpx_success(trace, possible_points)
51 with_recipient_locale trace.user do
52 @trace_name = trace.name
53 @trace_points = trace.size
54 @trace_description = trace.description
55 @trace_tags = trace.tags
56 @possible_points = possible_points
58 mail :to => trace.user.email,
59 :subject => I18n.t('notifier.gpx_notification.success.subject')
63 def gpx_failure(trace, error)
64 with_recipient_locale trace.user do
65 @trace_name = trace.name
66 @trace_description = trace.description
67 @trace_tags = trace.tags
70 mail :to => trace.user.email,
71 :subject => I18n.t('notifier.gpx_notification.failure.subject')
75 def message_notification(message)
76 with_recipient_locale message.recipient do
77 @to_user = message.recipient.display_name
78 @from_user = message.sender.display_name
80 @title = message.title
81 @readurl = url_for(:host => SERVER_URL,
82 :controller => "message", :action => "read",
83 :message_id => message.id)
84 @replyurl = url_for(:host => SERVER_URL,
85 :controller => "message", :action => "reply",
86 :message_id => message.id)
88 mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
89 :to => message.recipient.email,
90 :subject => I18n.t('notifier.message_notification.subject_header', :subject => message.title)
94 def diary_comment_notification(comment)
95 with_recipient_locale comment.diary_entry.user do
96 @to_user = comment.diary_entry.user.display_name
97 @from_user = comment.user.display_name
99 @title = comment.diary_entry.title
100 @readurl = url_for(:host => SERVER_URL,
101 :controller => "diary_entry",
103 :display_name => comment.diary_entry.user.display_name,
104 :id => comment.diary_entry.id,
105 :anchor => "comment#{comment.id}")
106 @commenturl = url_for(:host => SERVER_URL,
107 :controller => "diary_entry",
109 :display_name => comment.diary_entry.user.display_name,
110 :id => comment.diary_entry.id,
111 :anchor => "newcomment")
112 @replyurl = url_for(:host => SERVER_URL,
113 :controller => "message",
115 :display_name => comment.user.display_name,
116 :title => "Re: #{comment.diary_entry.title}")
118 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
119 :to => comment.diary_entry.user.email,
120 :subject => I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name)
124 def friend_notification(friend)
125 with_recipient_locale friend.befriendee do
128 mail :to => friend.befriendee.email,
129 :subject => I18n.t('notifier.friend_notification.subject', :user => friend.befriender.display_name)
133 def note_comment_notification(comment, recipient)
134 with_recipient_locale recipient do
135 @noteurl = browse_note_url(comment.note, :host => SERVER_URL)
136 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, I18n.locale)
137 @comment = comment.body
138 @owner = recipient == comment.note.author
139 @event = comment.event
142 @commenter = comment.author.display_name
144 @commenter = I18n.t("notifier.note_comment_notification.anonymous")
148 subject = I18n.t("notifier.note_comment_notification.#{@event}.subject_own", :commenter => @commenter)
150 subject = I18n.t("notifier.note_comment_notification.#{@event}.subject_other", :commenter => @commenter)
153 mail :to => recipient.email, :subject => subject
159 def with_recipient_locale(recipient)
160 old_locale = I18n.locale
163 I18n.locale = recipient.preferred_language_from(I18n.available_locales)
167 I18n.locale = old_locale
171 def from_address(name, type, id, digest)
172 if Object.const_defined?(:MESSAGES_DOMAIN) and domain = MESSAGES_DOMAIN
173 "#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>"