/
person_mailer.rb
78 lines (67 loc) · 2.78 KB
/
person_mailer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class PersonMailer < ActionMailer::Base
extend PreferencesHelper
def domain
@domain ||= PersonMailer.global_prefs.domain
end
def server
@server_name ||= PersonMailer.global_prefs.server_name
end
def password_reminder(person)
from "Password reminder <password-reminder@#{domain}>"
recipients person.email
subject formatted_subject("Password reminder")
body "person" => person
end
def message_notification(message)
from "Message notification <message@#{domain}>"
recipients message.recipient.email
subject formatted_subject("New message")
body "server" => server, "message" => message,
"preferences_note" => preferences_note(message.recipient)
end
def connection_request(connection)
from "Contact request <connection@#{domain}>"
recipients connection.person.email
subject formatted_subject("Contact request from #{connection.contact.name}")
body "server" => server,
"connection" => connection,
"url" => edit_connection_path(connection),
"preferences_note" => preferences_note(connection.person)
end
def blog_comment_notification(comment)
from "Comment notification <comment@#{domain}>"
recipients comment.commented_person.email
subject formatted_subject("New blog comment")
body "server" => server, "comment" => comment,
"url" =>
blog_post_path(comment.commentable.blog, comment.commentable),
"preferences_note" =>
preferences_note(comment.commented_person)
end
def wall_comment_notification(comment)
from "Comment notification <comment@#{domain}>"
recipients comment.commented_person.email
subject formatted_subject("New wall comment")
body "server" => server, "comment" => comment,
"url" => person_path(comment.commentable, :anchor => "wall"),
"preferences_note" =>
preferences_note(comment.commented_person)
end
def email_verification(ev)
from "Email verification <email@#{domain}>"
recipients ev.person.email
subject formatted_subject("Email verification")
body "server_name" => server,
"code" => ev.code
end
private
# Prepend the application name to subjects if present in preferences.
def formatted_subject(text)
name = PersonMailer.global_prefs.app_name
label = name.blank? ? "" : "[#{name}] "
"#{label}#{text}"
end
def preferences_note(person)
%(To change your email notification preferences, visit http://#{server}/people/#{person.to_param}/edit#email_prefs)
end
end