Operating System - HP-UX
1842656 Members
2103 Online
110194 Solutions
New Discussion

relay some application emails and not others

 
Tim Nelson
Honored Contributor

relay some application emails and not others

I have read through a number of posts and it is still clear as mud so please bear with.

sendmail 8.11.1

I have an application that I have configured to send its email to the localhost. I want the localhost to relay emails to certain domains or drop the rest.

i.e mail to mydomain.com should be forwarded
mail to anywhereelse.com should be dropped

It looks like configuring /etc/mail/relay-domains is the right way to go but...

BTW, it also seems that relaying should be disabled by default. In my standard installs it is not.. hmmmmm.

Any suggestions ?
5 REPLIES 5
Tim Nelson
Honored Contributor

Re: relay some application emails and not others

One thing I found while testing.

Warning "open relay" is not disabled by default. you must either comment out the
"FR-o /etc/mail/relay-domains" line in sendmail.cf or make sure there is a null file called /etc/mail/relay-domains



VK2COT
Honored Contributor

Re: relay some application emails and not others

Hello,

I can think of several possibilities.
One of them is yours (relay-domains).
Mimedefang, virtualtable, and other
possibilities exist.

Similar to your requirement, I had a project
where some hospital applications (Java-based)
needed to rewrite the email headers and
forward from localhost to somewhere else.
Java application was not able to do it
and the customer was desperate for a
solution.

Procmail was a simple choice and it still
works (after six-seven years since its implementation).

A short summary:

a) Set up some local account (or use the one
that you already have to send emails to
localhost). Let's assume it is named myuser.

b) Install Procmail.

c) Make sure that Procmail is used
as local Mail Delivery Agent in
/etc/mail/sendmail.cf (if you use
Sendmail as Mail Transfer Agent).

Check line that that starts with "Mlocal".

d) Set up a simple ~myuser/.procmailrc
RC file. Something like:

SHELL=/bin/sh
VERBOSE=off
LOG="
"
MAILDIR=/home/myuser/Mail
PMDIR=/home/myuser/.procmail
LOGFILE=/dev/null
INCLUDERC=$PMDIR/rc.myrecipe
#LOGABSTRACT=all

c) Set up Procmail recipe in ~homedir/.procmail/rc.myrecipe.
Something like:

:0
* ^To.*mydomain.com
{
:0 fhw
| formail -i"To: someaddr@mydomain.com" -i"From: myuser@mydomain.com"
:0
!someaddr@mydomain.com
}

:0
*
/dev/null

Then, all email star are sent to local user
myuser will pass through Procmail
recipes...

Enjoy life. Do not let problems worry you :)
This planet is so beautiful and we are
just a small part of it.

Cheers,

VK2COT
VK2COT - Dusan Baljevic
Tim Nelson
Honored Contributor

Re: relay some application emails and not others

Thanks Dusan, I will review these options.

For now I have completely disabled the relay in order to stop unwanted emails being delivered from the application.

The reason for doing this is an issue arose during a refresh of development that the application's active jobs were sending duplicate emails like production. Easy enough to turn off the jobs but there may be cases where a test needs to be run and the jobs re-enabled.

In lieu of reconfiguring all jobs and letting an email slip out we was the reason for my question.

I think the current solution for tests is going to drop all relays, then for testing they can use the local user account as an address ( which is not a relay). The local account/alias can then forward to the real off server address ( which is a local delivery ).

Still confusing as mud but works for now.

Procmail seems to be another good choice as I can configure per T0: address who gets mail and who does not.

Tim Nelson
Honored Contributor

Re: relay some application emails and not others

Below is a solution that I found.

The solution uses a mix of access_db and virtusertable.

1st recreate sendmail.cf to include access_db and virtusertable. Your new sendmail.cf will now have these options.

disable relaying either comment out like above or create the relay-hosts file and test.

use the access_db to restrict what users can send email through this server

e.g (access.list)
tim.nelson@abc.net RELAY
makemap -t hash access_map < access.list

use the virtusertable to alias where the mail goes.
e.g (user.list)
tim.nelson@abc.net tim.nelson@abc.com
makemap -t hash virtuser < user.list

must have abc.net in sendmail.cw in order for sendmail to look at the email and process the virtuser entries. And the user defined must be a local user on the server.

A little convoluted but it works.
Tim Nelson
Honored Contributor

Re: relay some application emails and not others

update.

Ran into one last issue with this configuration.

If the mail client is on the same server as the mail server then it seems as though the virtusertable does not get processed. Mail looks like it is processed just like it was local mail.

( this may sound like a "well ya" but, we are talking about a 3rd party client sending to a smtp server, it should not matter if it is on the same machine or not)

We are currenlty thinking of configuring two smtp servers and criss-crossing a-b and b-a.

Extra work for something I am sure is just a local mail rule that needs to be tweeked to use the virtualuser db.

Anyone have any thoughts ?