Skip to content

Sending emails from OFN

romale edited this page Nov 24, 2021 · 12 revisions

Requirements

To properly configure OFN we need to be able to send emails from the application using an SMTP server. First, follow these steps below:

  1. Create an account in an SMTP service provider like SendGrid, Mandrill, etc.
  2. Register your domain in the SMTP provider following its specific documentation

Configuring mail settings automatically

Mail settings get automatically configured but some environmental variables need to be provided for it to work.

In the secrets.yml of your OFN instance, make sure you set the appropriate values for the variables mail_host, mail_port, smtp_username, smtp_password. You can also configure variable mail_secure_connection. These values will be provided by your SMTP service provider.

Once done, you need to provision your instance. This will make them available for the OFN app. When deploying from ofn-install the db:seed rake task will create and configure the mail settings with these values.

Note: Sidekiq needs to be restarted for these new values to be picked up. This is done as part of every app deployment.

Creating a mail method from the UI

You no longer can configure the basic mail settings in the UI. You can configure a few values in the UI:

  • Enable mail delivery - you can use to enable/disable mail delivery in the app
  • Send mails as as your domain email like no-reply@ofn.coop
  • Send copy of all emails and Intercept email address

Test

  1. Click "Send Test Email" on the top right corner
  2. A green banner on the top should appear communicating that a test email has been sent to the super admin email address (ofn@example.com by default in development)
  3. Check your email to ensure that the email has been sent (check SPAM folder also)

Troubleshooting

Test email shows an error

Probably the SMTP settings are not correct or the SMTP provider is not able to send emails. Check the logs in the SMTP provider service for errors.

Test email works but other emails don't get sent (signup, etc.)

In /admin/mail_methods, on the right of each mail method listed there is a "send test email" button with an ✉️ icon. This button will send an email to the super admin and it's useful to test the SMTP configuration BUT keep in mind that it will not send the email using delayed_job. This is important since you may receive the test email but if for whatever reason the delayed_job process is not running all the other email will not get sent. Check that the delayed_job process is running.

I need to send emails from staging server

Many email services will not allow registering email accounts for sub-domains like info@staging.ofn.coop. The workaround is to use the same email account as in production (e.g. info@ofn.coop) and use a different API key. In this way, you'll be able to send emails from the same address but filter the SMTP logs by API key.

SMTP ports are blocked by your server provider

Some server providers are known to block SMTP ports by default. If you see the email successfully sent from log/staging.log or log/production.log check out its security settings and allow connections to the SMTP ports. You might need to reboot the machine; that's the case for Scaleway.

Clone this wiki locally