setting up WordPress mail on CentOS
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
.
-
Install
sendmail
if it is not already.Tip: to see if
sendmail
is already installed, run the commandwhich sendmail
. If you see something like the following, congrats, you already havesendmail
and can skip to step 2:$ which sendmail /usr/sbin/sendmail
To install, in a term enter
sudo yum install sendmail
and entery
when prompted. -
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 change123.456.78.90 myshortname
to123.456.78.90 myshortname mypublicdomain.com
. Edit/etc/hosts
in your favorite editor, e.g.,sudo vim /etc/hosts
. You might see an error like “sendmail[16614]: 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[16614]: 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
. -
Restart
sendmail
by enteringsudo service sendmail restart
.