Linux – How to configure sendmail to only send to specified domains

centosemaillinuxPHPsendmail

I have a local development server (centos) which I develop a number of websites on. Occasionally I need to test email sending scripts.

I want to avoid the development server from sending emails to anyone who doesn't have an email address with a particular domain (ie: jon@mydomain.com, mary@mydomain.com, etc). So, I would like to create a white list or rule on the server which prevents emails being sent to any email address that doesn't match mydomain.com.

I'm currently using PHP's built-in mail() function. But I imagine this is something more on the server level and I would like something that will manage ANY emails sent out from the server from any program/app/script/etc.

I can confirm that PHP is using /usr/sbin/sendmail.sendmail

Best Answer

here is how I managed to do it. In Sendmail, you need to modify the mailertable. Add the following:

alloweddomainname.com   alloweddomainname.com
.   error:

This will essentially send any emails to @alloweddomainname.com and error for anything else.

Related Topic