End to end testing of DKIM involves setting up DNS records on a real domain and might be a bit onerous for a test here.
1) Setup a moodle which sends real emails
2) Note the domain of the noreply user, eg lets assume it is noreply@moodle.myschool.edu.au and so the sending domain is moodle.myschool.edu.au
3) Choose a DKIM selector, this is arbitrary but is usually some sort of date related string such as '2020sep', set this in the 'emaildkimselector' field here:
/admin/settings.php?section=outgoingmailconfig
4) Turn on debugging:
$CFG->debug = (E_ALL | E_STRICT);
5) Send a test email (Note the /admin/testoutgoingmailconf.php overrides the debug level and will never emit these debug messages)
php -r "define('CLI_SCRIPT',1);require('config.php'); email_to_user((object)['id'=>-1,'email' => 'youremail@test.com'], core_user::get_support_user(), 'subject', 'body');"
6) Confirm that you get a debugging message similar to this:
Email DKIM selector chosen due to brendan+noreply@catalyst-au.net but no certificate found at /var/lib/sitedata/moodle.local/dkim/catalyst-au.net/2020sep10.private
7) Now setup a DKIM public and private key pair:
Now in sitedata we need to create a folder to hold the DKIM certificate with a subdirectory matching the domain:
mkdir -p /path/to/sitedata/dkim/moodle.myschool.edu.au
Next in this directory generate the private key and public key DNS record using the opendkim-genkey tool:
opendkim-genkey -b 2048 -r -s 2020sep -d moodle.myschool.edu.au -v
This should result in two files like this:
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.txt
/path/to/sitedata/dkim/moodle.myschool.edu.au/2020sep.private
8) Re test the emails to confirm that you see the DKIM signature in the email headers
Optional steps if you have a full proper domain and DNS records:
9) Add the DNS record with a short TTL created in the .txt file in step 5 to your domain. In the example above the record would go into
2020sep._domainkey.moodle.myschool.edu.au{{}}
10) Confirm that this record is available and correctly parsing using this 3rd party DKIM tool:
https://mxtoolbox.com/dkim.aspx
11) Wait some time for the ttl til filter through then send a second test email to a remote email which is know to do DKIM validation, (eg most of them, Gmail does)
12) Confirm using that remote email that the validation is correct, 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