Operating System - HP-UX
1755702 Members
3303 Online
108837 Solutions
New Discussion юеВ

sendmail and relaying question

 
SOLVED
Go to solution
Scott Van Kalken
Esteemed Contributor

sendmail and relaying question

I have a problem, and I'm not sure if I'm reading the docs properly.

I have sendmail running with DS set to our internal mail server. This is cool, if I email "root" it sends it on to our exchange server than on to me.

Is there a way to set sendmail up so that it performs relaying based on the email address?

For example:

mailx -s "foo.com test" foo@foo.com goes via the foo.com relay.


mailx -s "company.org" me@company.org goes via the relay company.org

Is it possible to relay dependant on the email address?

Any help appreciated.
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: sendmail and relaying question

Yes, this is possible but it is a bit tricky:

Here is what I do (in sendmail.cf):

Create a new macro for another relay. I will define a 'T' macro for this. The 'S' macro will be used for everything except

To make things clearer, I will define the 'M' (masqurade) macro.
-----------------------------
# who I masquerade as
DMchemfirst.com
# "Smart" relay host (may be null)
DSelmer

# Relay for local domain
DTcemgw1
------------------------------------
My plan is for everything that is NOT xxx@chemfirst.com to be sent via the 'S' (host elmer) relay; anything that is xxx@chemfirst will be sent via the 'T' (host cemgw1) relay.

Now down in the section of sendmail.cd just before 'S' ($S) macro is used; I make the following changes using instead the 'T' ($T) macro instead if I detect a local domain address. (I have also added a few rules if other related domains are found; they too use the 'T' relay. ekctech.com, firstchem.com, cfem.com)

Finally, if no local domains are detected we fall through to the 'normal' 'S' smart relay.
---------------------------------------
# pass names that have local domain to relay host $T
# 03/05/02 added ekctech, firstchem, cfem to relay $T
R$* < @ $m > $* $: $>95 < $T > $1 < @ $m > $2
R$* < @ ekctech.com > $* $: $>95 < $T > $1 < @ ekctech.com > $2
R$* < @ firstchem.com > $* $: $>95 < $T > $1 < @ firstchem.com > $2
R$* < @ cfem.com > $* $: $>95 < $T > $1 < @ cfem.com > $2

# pass names that still have a host to a smarthost (if defined)
R$* < @ $* > $* $: $>95 < $S > $1 < @ $2 > $3 glue on smarthost name
---------------------------------------------

If all of this looks very strange to you (and it should), I suggest that you purchase a copy of O'reilly's 'Sendmail'. That book will turn what is opaque to merely murky.

Regards, Clay



If it ain't broke, I can fix that.
Christopher Caldwell
Honored Contributor

Re: sendmail and relaying question

>Is it possible to relay dependant on the email address?

Yes - see mailertable [used to override/coerce mail routing by domain]
Format is like
domain.com smtp:nameof.your.host.com

and
virtusertable which will work on a user by user basis for inbound mail

Format is like
a@domain.com a@newplace.com
b@domain.com b@otherplace.com
c@otherdomain.com d@someplace.com

and
genericstable [like virtusertable for outbound mail

a@a.b.com a@a.com

Uncomment
either the virtusertable entries in sendmail.cf and/or mailterable entries in sendmail.cf and/or genericstable entries in sendmail.cf:

virtusertable:
# Virtual user table (maps incoming users)
Kvirtuser dbm /etc/mail/virtusertable

mailertable
# Mailer table (overriding domains)
Kmailertable dbm /etc/mail/mailertable

genericstable
# Generics table (mapping outgoing addresses)
Kgenerics dbm /etc/mail/genericstable

{Note for each feature, search for the feature {genericstable/mailertable/virtusertable} and make sure all of the supporting rulesets are uncommented (I'll include one for example:)
... Uncomment these rules ...

S90
#R$* <$- . $+ > $* $: $1$2 < $(mailertable .$3 $@ $1$2 $@ $2 $) > $4
#R$* <$~[ : $+ > $* $>95 < $2 : $3 > $4 check -- resolved?
#R$* < . $+ > $* $@ $>90 $1 . <$2> $3 no -- strip & try again
#R$* < $* > $* $: < $(mailertable . $@ $1$2 $) > $3 try "."
#R< $~[ : $+ > $* $>95 < $1 : $2 > $3 "." found?
#R< $* > $* $@ $2 no mailertable match


Scott Van Kalken
Esteemed Contributor

Re: sendmail and relaying question

It doesn't look that strange clay, my mind just went blank and I didn't have the book at work. :)

What you describe makes a lot of sense.

Thanks for the help.

Scott.