2

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

David
  • 841
  • 3
  • 14
  • 31

2 Answers2

1

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.

David
  • 841
  • 3
  • 14
  • 31
  • Have you considered using "catchall" local mailbox in default mailertable route? `. local:catchall` – AnFi Sep 17 '13 at 14:27
0

PHP mail() function sends messages according to MTA set as sendmail_path value in php.ini, by default, it's set to following:

sendmail_path = /usr/sbin/sendmail -t -i

on some systems it's a symlink to the binary of MTA, in my case it's sendmail-compatible binary of postfix MTA package, in other case it might be sendmail or qmail or whatever you use:

[root@giomacdesk ~]# ll /usr/sbin/sendmail
lrwxrwxrwx. 1 root root 21 ივლ  3 11:33 /usr/sbin/sendmail -> /etc/alternatives/mta
[root@giomacdesk ~]# ll /etc/alternatives/mta
lrwxrwxrwx. 1 root root 26 ივლ  3 11:33 /etc/alternatives/mta -> /usr/sbin/sendmail.postfix

So, according to this you can:

A. change sendmail_path to your custom script, write parser and filter messages accordingly. This will affect only outgoing messages sent via PHP mail() where sendmail_path was changed.

B. change configuration of mail server - this will affect all messages sent via MTA of your server, to do this you must check what is your server and configure it accordingly

In case of postfix:

  1. add following to the /etc/postfix/main.cf: transport_maps = hash:/etc/postfix/transport_maps

  2. create file /etc/postfix/transport_maps with following content:

     alloweddomain.com :
     * discard:
    
  3. hash: run postmap /etc/postfix/transport_maps

  4. restart postfix

GioMac
  • 4,544
  • 4
  • 27
  • 41
  • I can confirm that it's /usr/sbin/sendmail.sendmail – David Sep 17 '13 at 12:52
  • I'd make life easier - install postfix, remove sendmail, enable postfix: `yum install postfix -y;yum remove sendmail;chkconfig postfix on;service postfix start` – GioMac Sep 17 '13 at 12:55