Giving Drupal permission to send email on SELinux

I am currently working on a project which automates the process of creating newsletter emails from templates. Upon moving this project from my local working environment to a dev server, the Drupal site stopped being able to send emails. At first, I thought that it may be an issue with the mimemail module. The only error that the db log showed was "Error sending e-mail (from %from to %to)."

After finding troubleshooting of the mimemail module unsuccessful, my next step to troubleshoot the email functionality was to try to send an email with php using the devel module. This does not use any modules, it is strictly executing PHP. If you have admin_menu installed, you can hover over the home button in the top-left corner of your site, and go to 'Development' > 'Execute PHP Code,' and enter this code.

$to = "name@domain.com";
$subject = "Test email";
$body = "This is a test";
if (mail($to, $subject, $body)) {
echo("Message successfully sent!");
} else {
echo("Message delivery failed...");
}

If this succeeds, then your issue is with your module configuration. However, in my case, this failed as well. After hours of research, I discovered that it was actually an OS-level configuration issue. A cat of maillog in /var/log showed the following error:

postfix/sendmail[11129]: fatal: chdir /var/spool/postfix: Permission denied

SELinux in CentOS has a configuration parameter called httpd_can_sendmail, which gives Apache permission to send e-mail. You can check whether this is set to on/off using the following command:

/usr/sbin/getsebool httpd_can_sendmail

This will return "httpd_can_sendmail --> {on|off}." If this value is set to off, this may be the source of your issue. I was finally able to send email after issuing the following command and restarting the Apache service:

sudo setsebool -P httpd_can_sendmail 1