LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Other *NIX Forums > AIX
User Name
Password
AIX This forum is for the discussion of IBM AIX.
eserver and other IBM related questions are also on topic.

Notices


Reply
  Search this Thread
Old 07-16-2015, 10:08 AM   #1
amolpali
LQ Newbie
 
Registered: Jul 2015
Posts: 2

Rep: Reputation: Disabled
Restrict sendmail to send emails to only one domain


Hi,
I have sendmail running on AIX machine. It is using windows mail relay server to send emails internally within organization and externally on the web. It works all ok. However I want to restrict any user on AIX machine to send emails only to users in one domain e.g. abc@domain.com. So the emails directed to any other domain e.g. @gmail.com should not even reach to mail relay server and get blocked on AIX servers itself. Anyone has got any idea how can I achieve this?
 
Old 07-17-2015, 04:48 AM   #2
cliffordw
Member
 
Registered: Jan 2012
Location: South Africa
Posts: 509

Rep: Reputation: 203Reputation: 203Reputation: 203
Hi there,

You can do this with the "mailertable" feature.

This can be done by following these steps:

- Disable the "smart relay" in sendmail.cf (line starting with DS, and containing something like "DSsmtp:relay.example.com"). Comment this out, and replace it with a line containing only the letters DS with no value following it.
- Enable the "mailertable" feature, which configures relay hosts per domain. Do this by searching for "mailertable" in sendmail.cf, and uncommenting the "Kmailertable hash /etc/mail/mailertable" line, and the block of 5 rules below the comment "not local -- try mailer table lookup".
- Create an /etc/mail/mailertable file, containing something like this:

Code:
example.com   smtp:relay.example.com
.        error:nohost Mail to external domain is prohibited
Note that the left hand side (domain name) and right hand side (relay) are separated by a tab, not spaces. These rules tell sendmail that for mail destined for @example.com addresses, use the relay.example.com relay. For all other domains, return an error message (other options are described below).

- Build the database version of the mailertable file by running:

Code:
makemap hash /etc/mail/mailertable < /etc/mail/mailertable
The "error:nohost ..." mailer mentioned above can be replaced with other options, including:

- To discard the mail, replace everything from "error:..." with "local:nobody". The "local" mailer delivers mail to a local user or alias, and "nobody" is usually an alias for /dev/null in /etc/mail/aliases.
- If you want to send mail to an alternate local user, specify the username, for example "local:amolpali".
- If you want to keep the mail in a file instead, create an alias in /etc/mail/aliases, for example "remotemail: /tmp/badmailfile", run the newaliases command, and specify a mailer of "local:remotemail" in the mailertable.

Remember to rerun the makemap command after changing the mailertable file.

To test whether this works, try and send mail to a local user (without a domain name), a user at an allowed domain (amolpali@example.com in the example above), and to a domain not specifically allowed (like nobody@example.net). The local & allowed mail should be delivered. The external mail should not be delivered, but instead:

- If you are using the "error" mailer, the mail/mailx commands will return the error, and write the mail to the ~/dead.letter file.
- If you redirected the mail to a user or file, the mail should go there.
- If you discarded the mail ("local:nobody" mailer), you can use syslogd to test. Configure syslogd to write at least mail.info messages to a file, send a test message to an address at an outside domain (nobody@nowhere.co.za in the example below), and check the syslog output file. You should see an log entry like this:

Code:
Jan 30 12:11:25 buffy mail:info sendmail[16318522]: q0UABP7M16318522: from=root, size=47, class=0, nrcpts=1, msgid=<201201301011.q0UABP7M16318522@buffy.example.com>, relay=root@localhost
Jan 30 12:11:25 buffy mail:info sendmail[9764972]: q0UABP7M16318522: to=/dev/null, ctladdr=nobody@example.net (1/0), delay=00:00:00, xdelay=00:00:00, mailer=*file*, pri=120047, dsn=2.0.0, stat=Sent
Good luck!
 
3 members found this post helpful.
Old 07-17-2015, 09:31 AM   #3
amolpali
LQ Newbie
 
Registered: Jul 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Very useful answer cliffordw!
Thanks a lot
It's working perfectly after following your instructions.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
restrict sendmail to send emails to only one domain lakshminarayanan Linux - Newbie 1 03-21-2015 11:23 AM
Sendmail restrict by domain and ip address marcusone Linux - Server 1 07-31-2014 07:48 PM
Restrict users of a domain to send/receive mail from one particular domain tanveer Linux - Server 0 09-02-2007 02:01 AM
Qn: How to restrict in/out emails within a domain name/internal organisation only? rebel Red Hat 11 08-24-2004 07:25 AM
Qn: How to restrict in/out emails within a domain name/internal organisation only? rebel Linux - Security 1 08-18-2004 11:03 PM

LinuxQuestions.org > Forums > Other *NIX Forums > AIX

All times are GMT -5. The time now is 07:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration