forked from swlkr/roda-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.rb
64 lines (50 loc) · 1.16 KB
/
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
require './roda_app'
class Mailer < RodaApp
plugin :mailer, content_type: 'text/html'
plugin :render, escape: true, layout: './emails/layout'
request_delegate :mail, :on
if production?
Mail.defaults do
delivery_method :smtp, {
address: 'smtp.mailgun.org',
user_name: 'postmaster@your_project.com',
password: ENV['SMTP_PASSWORD'],
port: 587
}
end
else
Mail.defaults do
delivery_method :logger
end
end
Dir[File.join(__dir__, "mailers", "*.rb")].each do |file|
require file
end
def self.deliver_later(path)
SendEmailJob.perform_async path
end
def hostname
if development?
'http://localhost:9292'
else
'https://your_project.com'
end
end
route do
set_view_subdir 'emails'
from 'You <you@your_project.com>'
on 'users', Integer do |id|
@user = User[id]
no_mail! unless @user
to @user.email
subject '[your_project] Your login link is in inside'
@link = "#{hostname}#{session_path(@user)}"
mail 'signup' do
view 'signup'
end
mail 'login' do
view 'signup'
end
end
end
end