-
Notifications
You must be signed in to change notification settings - Fork 8
Outgoing Email
Rails already provides outgoing email functionality via ActionMailer. All we do is add a bit of configurability on top, by enabling app admins to set SMTP settings and some other sender information through the admin UI.
But this is something that could easily be configured through environment variables or Rails secrets, so why this sugar? Because 1) admins might actually benefit from being able to set/change these settings, and 2) for multi-tenanted apps, this would actually become essential as each tenant would ideally like to use their own SMTP server.
In fact, these settings do fall back on Rails secrets, which in turn (by default) defer to environment variables, so you have several layers and options for configuration.
To enable any mailer class to use the settings so configured, merely include the ConfigurableDeliveryMailer module as follows:
class SomeMailer < ActionMailer::Base
include ConfigurableDeliverMailer
# The rest of your code as usual
end
We have already modified the Devise mailer along these lines.
You may like to add/remove/modify the possible outgoing email settings that can be set via the admin console.
These settings are built on the 'app settings' functionality provided by this starter kit, which provides a convenient way to define any application level settings required by the app, as well as create forms within the admin console to let app admins set/change these settings. This means that:
- The outgoing email settings definition can be found in the /app/models/app_settings folder, at /app/models/app_settings/outgoing_email.rb (by convention, all app settings definitions must be placed in this directory)
- The corresponding form within the admin console can be found in the /app/assets/javascripts/templates/admin/controller/app_settings directory, at /app/assets/javascripts/templates/admin/controller/app_settings/outgoing_email.html (again placed by convention; note also the similarity in the two file names)
- An entry for the main 'App Settings' menu in the admin console can be found in the AppSettingsCtrl controller
Modify the first two files as desired. You should not really need to modify the AppSettingsCtrl controller. It is only for completeness that we mention it above. If you wish to set/change the fallback defaults, do so in either secrets.yml or, as the secrets defer (by default) to environment variables anyway, in your environment variables.
