-
Notifications
You must be signed in to change notification settings - Fork 1
/
mailer.rb
67 lines (51 loc) · 1.47 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
65
66
67
require 'sinatra'
require 'sinatra/json'
require 'sinatra/cross_origin'
require 'sinatra/jsonp'
require 'active_support'
require 'active_support/core_ext/object/blank.rb'
require 'action_mailer'
require 'uri'
require 'base64'
enable :sessions
set :port, 9494
ActionMailer::Base.raise_delivery_errors = true
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
# :address => "smtp.gmail.com",
# :port => 587,
# :domain => "example.com",
# :authentication => :plain,
# :user_name => "YOUR_EMAIL",
# :password => "YOUR_PASSWORD",
# :enable_starttls_auto => true
:address => "localhost", :port => 1025
}
ActionMailer::Base.view_paths = File.expand_path('views')
class Mailer < ActionMailer::Base
default from: '[email protected]'
layout false
def notification(form_data)
@form_data = form_data
@time = Time.now.getutc
mail(to: '[email protected]',
subject: "New message from #{@form_data['email']}",
template_path: 'mailer',
template_name: 'notification')
end
end
configure do
enable :cross_origin
end
post '/' do
Mailer.notification(params).deliver
redirect 'http://localhost:4567/#contact'
end
get '/' do
payloadStr = Base64.decode64(params['payload'])
puts payloadStr
payload = Rack::Utils.parse_nested_query payloadStr
puts payload.inspect
Mailer.notification(payload)
jsonp [{success: 'Message Sent'}], params['callback']
end