When I set up my Moodle Server, one of the things that I wanted to do was be able to send the emails to the students as well as logs and various system emails.
Creating your Relay
If you haven’t done so already, you need to install postfix first.
# dnf install postfix
Next you need to open the /etc/postfix/main.cf file in your favorite editor
# i /etc/postfix/main.cf
At the bottom, add the following lines:
# sets gmail as relay relayhost = [smtp.gmail.com]:587 # use tls smtp_use_tls=yes # use sasl when authenticating to foreign SMTP servers smtp_sasl_auth_enable = yes # path to password map file smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # list of CAs to trust when verifying server certificate smtp_tls_CAfile = /etc/ssl/certs/ca-ca-bundle.crt # eliminates default security options which are incompatible with gmail smtp_sasl_security_options =
# To correct gmail rejecting your email with something similar to “530 5.7.0 Must issue a STARTTLS command first.”
smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
And you will need to create a tls_policy file in /etc/postfix that has the following line
Then run postmap /etc/postfix/tls_policy to create the hash of the file.
Next you’ll have to edit (or create) the sasl_passwd file that’s used in the postfix configuration above
# vi /etc/postfix/sasl_passwd
The format of this file is this:
After creating this file, you need to run the postmap command to create the hash of the password file and then make sure that postfix owns the files (as they are created by root originally).
chown postfix /etc/postfix/sasl_passwd*
chown postfit /etc/postfix/tls-policy*
Finally restart postfix using this command:
systemctl restart postfix.service
Testing your configurations
If everything worked correctly, you should be able to test your mail setup by sending an email from the command line. There are multiple methods for this, but I’ll show you two of them here.
The first method uses the mail command. (you should be able to do this as either root or a regular user) email@example.com should be replaced with your intended recipient’s email address.
mail -s “Subject: Test email from linux server” firstname.lastname@example.org
The editor will open up, so you can type a message in the body. You’ll use CTRL+D or enter a “.” to exit this editor.
Next, if you want to CC anyone, you can add their email addresses, and/or press CTRL+D to exit this portion.
The email should send. Check your inbox (and spam folders) to see if it’s arrived. If not, you can check /var/log/maillog (or in /var/log/mail) to find out what’s wrong.
My thanks to a number of sites, each of which provided me some of the information to get this done. I merely cleaned it up to and pasted it together to work on Moodle with this version of Fedora.