-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathemail.rb
35 lines (30 loc) · 1003 Bytes
/
email.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
require 'pony'
require 'json'
Pony.options = {
:from => 'noreply@elevatoralerts.com',
:via => :smtp,
:via_options => {
:address => 'smtp.sendgrid.net',
:port => '587',
:domain => 'mail.elevatoralerts.com',
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:authentication => :plain,
:enable_starttls_auto => true
}
}.freeze
class Email
def self.mail(opts = {})
to = opts.fetch(:to)
subject = opts.fetch(:subject)
body = opts.fetch(:body)
# Can't find the opentrack setting in sendgrid's web dashboard, so disable it here
headers = { "X-SMTPAPI" => { :filters => { :opentrack => { :settings => { :enable => 0 } } } }.to_json }
#Keen.publish("email", to: to, subject: subject)
if ENV['NO_EMAIL']
puts "Email is currently disabled, or we'd send: #{to}\nsubject:#{subject}\nbody:\n#{body}"
else
Pony.mail(:to => to, :subject => subject, :body => body, :headers => headers)
end
end
end