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 @locale = user.preferred_language_from(I18n.available_locales)
10 # If we are passed an email address verification token, create
11 # the confirumation URL for account activation.
13 # Otherwise the email has already been verified e.g. through
14 # a trusted openID provider and the account is active and a
15 # confirmation URL is not needed.
17 @url = url_for(:host => SERVER_URL,
18 :controller => "user", :action => "confirm",
19 :display_name => user.display_name,
20 :confirm_string => token.token)
23 mail :to => user.email,
24 :subject => I18n.t('notifier.signup_confirm.subject', :locale => @locale)
27 def email_confirm(user, token)
28 @locale = user.preferred_language_from(I18n.available_locales)
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', :locale => @locale)
38 def lost_password(user, token)
39 @locale = user.preferred_language_from(I18n.available_locales)
40 @url = url_for(:host => SERVER_URL,
41 :controller => "user", :action => "reset_password",
42 :token => token.token)
44 mail :to => user.email,
45 :subject => I18n.t('notifier.lost_password.subject', :locale => @locale)
48 def gpx_success(trace, possible_points)
49 @locale = trace.user.preferred_language_from(I18n.available_locales)
50 @trace_name = trace.name
51 @trace_points = trace.size
52 @trace_description = trace.description
53 @trace_tags = trace.tags
54 @possible_points = possible_points
56 mail :to => trace.user.email,
57 :subject => I18n.t('notifier.gpx_notification.success.subject', :locale => @locale)
60 def gpx_failure(trace, error)
61 @locale = trace.user.preferred_language_from(I18n.available_locales)
62 @trace_name = trace.name
63 @trace_description = trace.description
64 @trace_tags = trace.tags
67 mail :to => trace.user.email,
68 :subject => I18n.t('notifier.gpx_notification.failure.subject', :locale => @locale)
71 def message_notification(message)
72 @locale = message.recipient.preferred_language_from(I18n.available_locales)
73 @to_user = message.recipient.display_name
74 @from_user = message.sender.display_name
76 @title = message.title
77 @readurl = url_for(:host => SERVER_URL,
78 :controller => "message", :action => "read",
79 :message_id => message.id)
80 @replyurl = url_for(:host => SERVER_URL,
81 :controller => "message", :action => "reply",
82 :message_id => message.id)
84 mail :from => from_address(message.sender.display_name, "m", message.id, message.digest),
85 :to => message.recipient.email,
86 :subject => I18n.t('notifier.message_notification.subject_header', :subject => message.title, :locale => @locale)
89 def diary_comment_notification(comment)
90 @locale = comment.diary_entry.user.preferred_language_from(I18n.available_locales)
91 @to_user = comment.diary_entry.user.display_name
92 @from_user = comment.user.display_name
94 @title = comment.diary_entry.title
95 @readurl = url_for(:host => SERVER_URL,
96 :controller => "diary_entry",
98 :display_name => comment.diary_entry.user.display_name,
99 :id => comment.diary_entry.id,
100 :anchor => "comment#{comment.id}")
101 @commenturl = url_for(:host => SERVER_URL,
102 :controller => "diary_entry",
104 :display_name => comment.diary_entry.user.display_name,
105 :id => comment.diary_entry.id,
106 :anchor => "newcomment")
107 @replyurl = url_for(:host => SERVER_URL,
108 :controller => "message",
110 :display_name => comment.user.display_name,
111 :title => "Re: #{comment.diary_entry.title}")
113 mail :from => from_address(comment.user.display_name, "c", comment.id, comment.digest),
114 :to => comment.diary_entry.user.email,
115 :subject => I18n.t('notifier.diary_comment_notification.subject', :user => comment.user.display_name, :locale => @locale)
118 def friend_notification(friend)
119 @locale = friend.befriendee.preferred_language_from(I18n.available_locales)
122 mail :to => friend.befriendee.email,
123 :subject => I18n.t('notifier.friend_notification.subject', :user => friend.befriender.display_name, :locale => @locale)
126 def note_comment_notification(comment, recipient)
127 @locale = recipient.preferred_language_from(I18n.available_locales)
128 @noteurl = browse_note_url(comment.note, :host => SERVER_URL)
129 @place = Nominatim.describe_location(comment.note.lat, comment.note.lon, 14, @locale)
130 @comment = comment.body
131 @owner = recipient == comment.note.author
134 @commenter = comment.author.display_name
136 @commenter = I18n.t("notifier.note_comment_notification.anonymous")
140 subject = I18n.t('notifier.note_comment_notification.subject_own', :commenter => @commenter)
142 subject = I18n.t('notifier.note_comment_notification.subject_other', :commenter => @commenter)
145 mail :to => recipient.email, :subject => subject
150 def from_address(name, type, id, digest)
151 if Object.const_defined?(:MESSAGES_DOMAIN) and domain = MESSAGES_DOMAIN
152 "#{name} <#{type}-#{id}-#{digest[0,6]}@#{domain}>"