Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

User:Brendan Heywood/DKIM: Difference between revisions

From MoodleDocs
No edit summary
(Replaced content with "This was a temporary page until MDL-69513 landed, now please see: https://docs.moodle.org/en/Mail_configuration#DKIM https://tracker.moodle.org/browse/MDL-69513")
 
Line 1: Line 1:
This was a temporary page until MDL-69513 landed, now please see:


== DKIM ==
https://docs.moodle.org/en/Mail_configuration#DKIM


For advanced DKIM setup this is usually done at the MTA such as postfix eg using a 'milter' like opendkim.
https://tracker.moodle.org/browse/MDL-69513
 
However there are advantages to doing this in Moodle directly such as when you have limited control over the way your email is being sent. Also by having it in Moodle it can be easier to manage.
 
In 3.10 / 4.0 a new setting was added that makes it possible to sign emails at the Moodle level and it requires setting up the private certificates and putting them in a known location where Moodle can find them. Because emails could be sent from a variety of From email addresses the location contains the domain in it's path and you can provide as many certificates as needed but this is an uncommon use case.
 
== The most common setup ==
 
The simplest and fairly typical setup is where all emails are sent from the noreply email. In this setup we will give instructions on a linux setup such as debian or ubuntu.
 
<code php>
$CFG->noreplyaddress = 'noreply@moodle.myschool.edu.au'
</code>
 
In this case you need to choose a DKIM selector which is arbitrary but is often based on a date as the best practice is to rotate them on a periodic basis.
 
Lets say we have chosen a selector of '2020sep'.
 
Now in sitedata we need to create a folder to hold the DKIM certificate with a subdirectory matching the domain:
 
<code php>
mkdir -p /path/to/sitedata/dkim/moodle.myschool.edu.au
</code>
 
Next in this directory generate the private key and public key DNS record using the opendkim-genkey tool:
 
<code php>
opendkim-genkey -b 2048 -r -s 2020sep -d moodle.myschool.edu.au -v
</code>
 
This should result in two files like this:
 
<code php>
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.txt
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.private
</code>
 
Only the .private file is used by Moodle, the .txt file is the TXT record which you need to add to your DNS. To confirm that it is all correct there is a great public tool where you can enter the domain and DKIM selector and it will confirm the record looks like it is in the correct shape.
 
https://mxtoolbox.com/dkim.aspx
 
Once this is in place then use the email testing tool in moodle to send a test email, it can be useful to turn on the debugsmtp setting.
 
/admin/testoutgoingmailconf.php
 
You should see the DKIM signature in the email headers. The email server receiving the email should also have validated this signature as well and added another header with the results of this validation.
 
ie in Gmail open the email, click the '...' on the right, then 'Show original' and in the headers it should say:
 
DKIM: 'PASS' with domain moodle.myschool.edu.au

Latest revision as of 12:15, 14 June 2021