diff options
Diffstat (limited to 'config/email.cr')
-rw-r--r-- | config/email.cr | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/config/email.cr b/config/email.cr new file mode 100644 index 0000000..7c87544 --- /dev/null +++ b/config/email.cr @@ -0,0 +1,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 |