-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathuser_mailer.rb
More file actions
52 lines (43 loc) · 1.55 KB
/
Copy pathuser_mailer.rb
File metadata and controls
52 lines (43 loc) · 1.55 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
class UserMailer < ApplicationMailer
include WithCertificateRender
def welcome_email(user, organization)
with_locale(user, organization) do
organization_name = organization.display_name || t(:your_new_organization)
build_email t(:welcome, name: organization_name), { inline: organization.welcome_email_template }, from: organization.welcome_email_sender
end
end
def we_miss_you_reminder(user, cycles)
with_locale(user) do
build_email t(:we_miss_you), "#{cycles.ordinalize}_reminder"
end
end
def no_submissions_reminder(user)
with_locale(user) do
build_email t(:start_using_mumuki), 'no_submissions_reminder'
end
end
def delete_account(user)
with_locale(user) do
build_email t(:delete_account_mumuki), 'delete_account'
end
end
def certificate(certificate)
with_locale certificate.user, certificate.organization do
attachments[certificate.filename] = pdf_for(certificate)
mail to: certificate.user.email, subject: t(:certificate)
end
end
def with_locale(user, organization = nil, &block)
@user = user
@unsubscribe_code = User.unsubscription_verifier.generate(user.id)
@organization = organization || user.last_organization
I18n.with_locale(@organization.locale, &block)
end
private
def build_email(subject, template, **options)
mail options.compact.merge(to: @user.email,
subject: subject,
content_type: 'text/html',
body: render(template))
end
end