blob: 7c875449bf3e3c2686b116ba4624ee7ac3a68c31 (
plain)
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
|
require "carbon_sendgrid_adapter"
BaseEmail.configure do |settings|
if LuckyEnv.production?
# If you don't need to send emails, set the adapter to DevAdapter instead:
#
# settings.adapter = Carbon::DevAdapter.new
#
# If you do need emails, get a key from SendGrid and set an ENV variable
send_grid_key = send_grid_key_from_env
settings.adapter = Carbon::SendGridAdapter.new(api_key: send_grid_key)
elsif LuckyEnv.development?
settings.adapter = Carbon::DevAdapter.new(print_emails: true)
else
settings.adapter = Carbon::DevAdapter.new
end
end
private def send_grid_key_from_env
ENV["SEND_GRID_KEY"]? || raise_missing_key_message
end
private def raise_missing_key_message
puts "Missing SEND_GRID_KEY. Set the SEND_GRID_KEY env variable to 'unused' if not sending emails, or set the SEND_GRID_KEY ENV var.".colorize.red
exit(1)
end
|