Testing email

Getting set up

On new installs, Totara uses the default PHP method of sending mail. 

You can define an SMTP server (as well as other email configuration) on the Outgoing mail configuration page which can be found via the Admin menu > Server > Email.

For site setup and development there are a number of options available to ensure that emails are sent correctly and to allow the content of sent emails to be checked. Importantly these options can also ensure that emails are not sent inadvertently.

Here are some of the options.

Config setting ‘noemailever’

$CFG->noemailever = true;

This setting disables the sending of emails at the point of the emails being sent. This is useful when testing production data in a test environment.

This setting should never be used for production sites.

Config setting ‘divertallemailsto’

$CFG->divertallemailsto = 'developer@example.com';

This will force Totara to divert all email to the specified address. You can use this in conjunction with divertallemailsexcept, which is a comma-separated list of email addresses or regular expressions that you want to exclude from the diversion.

$CFG->divertallemailsexcept = 'tester@example.com, developer(\+.*)?@example.com';

Mailcatcher

Mailcatcher catches all sent mail and stores it for display within a web browser.

The smtphosts setting will need to be set accordingly, e.g.:

$CFG->smtphosts = ‘localhost:1025’;

Further information can be found at https://mailcatcher.me.

Maildev

Maildev is alternative to mailcatcher solution and is easy to get started.

Install maildev via npm:

npm install -g maildev


Open new terminal tab and start maildev:

maildev


Configure your Totara instance to use maildev:

config.php
$CFG->smtphosts = ‘localhost:1025’;


Open maildev web interface in browser :

http://localhost:1080/