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.

  1. Install sendmail if it is not already.

    Tip: to see if sendmail is already installed, run the command which sendmail. If you see something like the following, congrats, you already have sendmail and can skip to step 2:

     $ which sendmail
     /usr/sbin/sendmail
    

    To install, in a term enter sudo yum install sendmail and enter y when prompted.

  2. 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 to 123.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.

  3. 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”.

  4. 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.

  5. Restart sendmail by entering sudo service sendmail restart.