user_mailer.rb
2.67 KB
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
class UserMailer < ApplicationMailer
include EmailTemplateHelper
def activation_email_notify(user)
self.environment = user.environment
user_email = "#{user.login}@#{user.email_domain}"
@name = user.name
@email = user_email
@webmail = MailConf.webmail_url(user.login, user.email_domain)
@url = url_for(:host => user.environment.default_hostname, :controller => 'home')
mail(
to: user_email,
from: "#{user.environment.name} <#{user.environment.contact_email}>".html_safe,
subject: _("[%{environment}] Welcome to %{environment} mail!").html_safe % { :environment => user.environment.name }
)
end
def activation_code(user)
self.environment = user.environment
@recipient = user.name
@activation_code = user.activation_code
@url = user.environment.top_url
@redirection = (true if user.return_to)
@join = (user.community_to_join if user.community_to_join)
mail_with_template(
from: "#{user.environment.name} <#{user.environment.contact_email}>",
to: user.email,
subject: _("[%s] Activate your account").html_safe % [user.environment.name],
template_params: {:environment => user.environment, :activation_code => @activation_code, :redirection => @redirection, :join => @join, :person => user.person, :url => @url},
email_template: user.environment.email_templates.find_by_template_type(:user_activation),
)
end
def signup_welcome_email(user)
self.environment = user.environment
@body = user.environment.signup_welcome_text_body.gsub('{user_name}', user.name)
email_subject = user.environment.signup_welcome_text_subject
mail(
content_type: 'text/html',
to: user.email,
from: "#{user.environment.name} <#{user.environment.contact_email}>".html_safe,
subject: email_subject.blank? ? _("Welcome to environment %s").html_safe % [user.environment.name] : email_subject,
body: @body
)
end
def profiles_suggestions_email(user)
self.environment = user.environment
@recipient = user.name
@url = user.environment.top_url
@people_suggestions_url = user.people_suggestions_url
@people_suggestions = user.suggested_people.sample(3)
@communities_suggestions_url = user.communities_suggestions_url
@communities_suggestions = user.suggested_communities.sample(3)
mail(
content_type: 'text/html',
to: user.email,
from: "#{user.environment.name} <#{user.environment.contact_email}>".html_safe,
subject: _("[%s] What about grow up your network?").html_safe % user.environment.name
)
end
class Job < Struct.new(:user, :method)
def perform
UserMailer.send(method, user).deliver
end
end
end