Today at work I set up a WordPress install on CentOS Linux so that it could send email. It’s pretty useful and almost required to have this working, since if you forget your password, WordPress needs to send you an email to reset it. That’s how I discovered mail wasn’t set up correctly, actually: a user tried to reset their password and WordPress gave an error about “email could not be sent”, and no email was received. Fortunately it was pretty easy to fix.
Throughout the process, as I tried different things, it was helpful to monitor the mail log by running
sudo tail /var/log/maillog.
sendmailif it is not already.
Tip: to see if
sendmailis already installed, run the command
which sendmail. If you see something like the following, congrats, you already have
sendmailand can skip to step 2:
$ which sendmail /usr/sbin/sendmail
To install, in a term enter
sudo yum install sendmailand enter
Make sure your host name is set in
/etc/hosts. Your server IP address should be associated with more than just a shortname. For example, you might change
123.456.78.90 myshortname mypublicdomain.com. Edit
/etc/hostsin your favorite editor, e.g.,
sudo vim /etc/hosts. You might see an error like “sendmail: My unqualified host name (myshortname) unknown; sleeping for retry” if this is not correct.
If you’re using Apache as your server, ensure it can send mail by running
sudo setsebool httpd_can_sendmail=on. Otherwise you’ll see errors like “sendmail: NOQUEUE: SYSERR(apache): can not chdir(/var/spool/clientmqueue/): Permission denied”.
I restarted Apache at this point. I don’t know if this was necessary, but I did it with the command
sudo /etc/init.d/httpd restart.
sudo service sendmail restart.