Sending transactional emails
When you followed the quickstart, you configured your Amazon SES credentials to send transactional emails.
On top of that, your RailsFast app is configured to send beautiful transactional emails using the goodmail gem by default. So instead of sending boring, ugly, plaintext emails -- you send well-designed emails that look good on all email clients:
Your user auth emails, payment-related emails, organization invitation emails, and account security emails (new device sign-in, repeated failed logins, a sign-in method added or removed, account banned) come already configured and working out of the box, in English and Spanish.
You can view and edit all those emails:
app/mailers/devise_goodmailer.rbfordevise-related emails (user authentication)app/mailers/pay_goodmailer.rbforpay-related emails (payments & subscriptions)app/mailers/organization_invitation_goodmailer.rbfor team invitation emailsapp/mailers/user_goodmailer.rbfor account security and lifecycle emails
Every email is written in its recipient's language (their saved locale), not the language of whoever triggered it. ApplicationMailer gives your own mailers the same behaviour through recipient_locale(user) and t_in_locale(locale, key); see Translations (i18n).
Outgoing mail is sent from noreply@ your domain, with replies going to the support_email in config/railsfast/railsfast.yml, so never hardcode an address in a mailer.
If you're adding a normal Rails mailer, use Goodmail's Action Mailer helper inside the mailer action:
class UserMailer < ApplicationMailer
def welcome(user)
@user = user
goodmail_mail(to: @user.email, subject: "Welcome!") do
h1 "Welcome aboard, #{@user.name}!"
text "We're thrilled to have you join the community."
button "Go to Dashboard", dashboard_url
sign
end
end
end
For one-off emails outside a mailer class, you can also compose and deliver directly:
mail = Goodmail.compose(
to: recipient.email,
from: "'#{Goodmail.config.company_name} Support' <[email protected]>",
subject: "Welcome!",
) do
h1 "Welcome aboard, #{recipient.name}!"
text "We're thrilled to have you join the community."
button "Go to Dashboard", user_dashboard_url(recipient)
sign
end
mail.deliver_now
You can customize all transactional emails however you want! Add animated GIFs, change the text, make new emails... make sure to read the goodmail gem docs to know everything that's possible.
Addresses are checked before they ever receive an email: sign-up and email changes refuse throwaway domains and catch typos. See Email address checks.
If you don't like goodmail, or if you'd like to use your own email templates, you can still use Rails' ActionMailer -- goodmail is just an add-on, doesn't replace Action Mailer, you can keep writing emails with Action Mailer if that's what you like!