I need some help for configuring sendmail to forward emails
to another mail server. I am mentioning the details below.
1. When any user sends an email to a particular domain (eg: TO ADDRESS
is "a...@particulardomain.com"), then my sendmail should act as a smart
host and forward the request to a different mail server. (Only emails
SEND to that specific domain)
2. When a Specific User (From Address: "speci...@mydomain.com")sends
an email to any address then that also should be forwarded to a
different mail server.
Can anyone please help me for solving this.
Thanks & Regards,
Biju
If you are truly needing "this domain goes here" (despite what MX
records say) you can easily do this with MailerTable.
> 2. When a Specific User (From Address: "speci...@mydomain.com")
> sends an email to any address then that also should be
> forwarded to a different mail server.
Are you saying that when you are relaying email from your user base you
want to SmartHost out through said server (from MailerTable above) when
the sender is from the domain in question no matter who the recipient
domain(s) is (are)?
Grant. . . .
Hi Grant
Thanks a lot for the information.
Whatever you told for my second question is true.
what ever emails a specific user (us...@mydomain.com) is sending, all
those emails (no matter who all are the recepients) should be
forwarded by my email server to another email server (all permissions
are there for me in the second email server)
Also Grant i have one more question.
1. IF any user is sending emails to anyone with a SPECIFIC SUBJECT or
a SPECIFIC UNIQUE STRING in the BODY, my email server should forward
such emails to the another email server (ONLY EMAILS WITH SPECIFIC
SUBJECTS OR UNIQUES STRING IN THE BODY should be forwarded),
rest all emails should use my email server for sending. Is there any
way to do this, by writing a rule set or so?
Thanks & Regards,
Biju
You are welcome.
> Whatever you told for my second question is true.
>
> what ever emails a specific user (us...@mydomain.com) is sending, all
> those emails (no matter who all are the recepients) should be
> forwarded by my email server to another email server (all permissions
> are there for me in the second email server)
Ok...
> Also Grant i have one more question.
>
> 1. IF any user is sending emails to anyone with a SPECIFIC SUBJECT or
> a SPECIFIC UNIQUE STRING in the BODY, my email server should forward
> such emails to the another email server (ONLY EMAILS WITH SPECIFIC
> SUBJECTS OR UNIQUES STRING IN THE BODY should be forwarded), rest all
> emails should use my email server for sending. Is there any way to do
> this, by writing a rule set or so?
Are you wanting this new re-routing based on Subject / Body content to
be in addition to your previous question(s)?
Either way it sounds like you are wanting to conditionally alter the
server the message is sent to, be it by sender and / or subject content
and / or or body content. (This on top of the MailerTable capability.)
I'm not sure how to go about what you are wanting to do. I think you
are going to have to use a milter to alter the ""relay (where Sendmail
sends the message to). Presuming that this can be done (others on this
list can better help you here) you will need to write a milter (or some
Perl for MIMEDefang) to conditionally do this for you.
I will be very surprised if stock Sendmail can touch the later part(s)
of your request with out the help of a milter or some serious customization.
Grant. . . .
Hi
Thanks for the information Grant
Actually I tried writing a rule set. anyway i was able to filter based
on the subject. But i am not sure how to forward such filtered mail to
another SMTP Server.
I did some thing like below
LOCAL_CONFIG
LOCAL_RULESETS
HSubject: $>Check_Subject
SCheck_Subject
R$*CRAZY $#error $: "Mails with the subject CRAZY is
Rejected"
I was just testing to find if the email send to anyone with the
subject "CRAZY" is rejected and this worked fine.
so that means the subject is filtered.
Now i am thinking how to forward the same to a different mail server
Instead of "$#error" I tried
$#smtp $@ anothermailserver.com
But didnt get through. Is there any way to write a rule set to forward
emails to another mail server
Please do help
Regards
Biju
> Thanks for the information Grant
>
> Actually I tried writing a rule set. anyway i was able to filter based
> on the subject. But i am not sure how to forward such filtered mail to
> another SMTP Server.
> I did some thing like below
>
> LOCAL_CONFIG
> LOCAL_RULESETS
> HSubject: $>Check_Subject
> SCheck_Subject
> R$*CRAZY $#error $: "Mails with the subject CRAZY is
> Rejected"
>
> I was just testing to find if the email send to anyone with the
> subject "CRAZY" is rejected and this worked fine.
> so that means the subject is filtered.
> Now i am thinking how to forward the same to a different mail server
> Instead of "$#error" I tried
>
> $#smtp $@ anothermailserver.com
>
> But didnt get through. Is there any way to write a rule set to forward
> emails to another mail server
> Please do help
>
>
> Regards
> Biju
Use storage -map to store result of Check_Subject -ruleset to macro
and use that macro on ruleset 0 (or ruleset called from ruleset 0).
You may want register macro name to $={persistentMacros} class,
so that it is preserved on queued mail.
/ Kari Hurtta
(doc/op/op.me)
___________________________________________________________
+‐‐‐+
‐‐>| 0 |‐‐>resolved address
/ +‐‐‐+
/ +‐‐‐+ +‐‐‐+
/ ‐‐‐‐>| 1 |‐‐>| S |‐‐
+‐‐‐+ / +‐‐‐+ / +‐‐‐+ +‐‐‐+ \ +‐‐‐+
addr‐‐>| 3 |‐‐>| D |‐‐ ‐‐‐>| 4 |‐‐>msg
+‐‐‐+ +‐‐‐+ \ +‐‐‐+ +‐‐‐+ / +‐‐‐+
‐‐‐>| 2 |‐‐>| R |‐‐
+‐‐‐+ +‐‐‐+
Figure 1 — Rewriting set semantics
D — sender domain addition
S — mailer‐specific sender rewriting
R — mailer‐specific recipient rewriting
____________________________________________________________
Surely this doesn't work unless you use DeliveryMode=queue (and
$={persistentMacros}) - S0 is processed and the routing decision(s)
taken before the headers are seen.
--Per Hedeland
p...@hedeland.org
Hi Karri & Per
Thanks a lot for the informations. I tried to write the rule sets
as per your email, which i am mentioning below. I am not sure if this
is the way, that you actually told.
LOCAL_CONFIG
Kstorage macro
HSubject: $>Check_Subject
C{persistentMacros} {subj_exist}
LOCAL_RULESETS
SCheck_Subject
R$*CRAZY $: $(storage {subj_exist} $@ YES $) $1
Scheck_eoh
R$* $: < $&{subj_exist} >
R$* $: $(storage {subj_exist} $) $1
R<YES> $#error $: "Mails with the subject CRAZY is
Rejected"
I changed the value of "O DeliveryMode=background" to "O
DeliveryMode=queue" in sendmail.cf
This worked fine. But i am not sure how to use $#smtp.
Can you please have a look on the above rule set, and please tell me
if this is the way that you suggested and if so how to forward the
email with subject "CRAZY" to another email server. If this is not the
way the rule set is to be written, pls can you rectify the same
Thanks & Regards,]
Biju
Seems OK (I assume your check_eoh ruleset is just for testing).
>I changed the value of "O DeliveryMode=background" to "O
>DeliveryMode=queue" in sendmail.cf
You can do this from .mc with confDELIVERY_MODE (and I assume you
realize that it means that all mail will be queued and sent/delivered
only on queue runs).
>This worked fine. But i am not sure how to use $#smtp.
>Can you please have a look on the above rule set, and please tell me
>if this is the way that you suggested and if so how to forward the
>email with subject "CRAZY" to another email server.
Custom routing rules go in LOCAL_RULE_0 in your .mc. Something like this
might work:
LOCAL_RULE_0
R$* $: $1 $| $&{subj_exist} check macro
R$* $| YES $#esmtp $@ another.server. $: $1 match, reroute
R$* $| $* $1 no match
--Per Hedeland
p...@hedeland.org
Thanks a lot for the information. That was really terrific and
it did the job.
I did the end of headers check for testing and i was not at all sure
how to do the routing using Rule Set 0
Once again thanks a lot for this
Cheers
Biju
I am sending this mail seeking some more help from your side.
The Ruleset used in my sendmail configuration is something as shown
below and this works fine for whatever i was planning for. This works
in the following way.
If the From address is ("mailuser1" or "mailuser2") AND the subject is
"crazyboy" then the mail is forwarded to "mail.testext.com"
For all other users with the same subject ("crazyboy") or any other
subject OR For the same users (mailuser1 & mailuser2) with any
different subject
then the mail is NOT forwarded to "mail.testext.com" and the mails are
send via the local mail server.
And all things works fine. Now i have an additional task to be
achieved in this. But i am not sure how to.
The requirement is "If any user other than "mailuser1" and "mailuser2"
sends an email to anyone with the subject "crazyboy" then instead of
sending the email via the local mail server, an error should pop up
(something like "pls don't use the subject crazyboy"). (If the user
uses a different subject, the mail should be send by the local mail
server as it is working now. Only if the From address is : "mailuser1"
or "mailuser2" AND subject is "crazyboy" the error should pop up)
LOCAL_CONFIG
Kstorage macro
HSubject: $>Check_Subject
HFrom: $>Check_From
C{persistentMacros} {subj_exist}
C{persistentMacros} {from_exist}
LOCAL_RULESETS
SCheck_From
R$* $: $| $>canonify $1
R$*$|mailuser1 $+ $* $: $(storage {from_exist} $@ YES $) $|mailuser1
$2 $3
R$*$|mailuser2 $+ $* $: $(storage {from_exist} $@ YES $) $|mailuser2
$2 $3
SCheck_Subject
R$*CRAZYBOY $* $: $(storage {subj_exist} $@ YES $) $1 CRAZYBOY
$2
LOCAL_RULE_0
R$* $: $1 $|$&{subj_exist} check macro
R$*$|YES $: $1 $|$&{from_exist} check macro
R$*$|YES $#esmtp $@mail.testext.com.$: $1 match, reroute
R$*$|$*
$1 no
match
Can you please help me for achieving this.
Thanks & Regards,
Biju
>The Ruleset used in my sendmail configuration is something as shown
>below and this works fine for whatever i was planning for. This works
>in the following way.
>
>If the From address is ("mailuser1" or "mailuser2") AND the subject is
>"crazyboy" then the mail is forwarded to "mail.testext.com"
I doubt that you have a requirement to check the From: *header* -
checking the envelope sender address (available as $&f) makes things
simpler (and the envelope sender is marginally less trivial to spoof).
>The requirement is "If any user other than "mailuser1" and "mailuser2"
>sends an email to anyone with the subject "crazyboy" then instead of
>sending the email via the local mail server, an error should pop up
Sendmail won't pop up anything.:-) At best you can get a reject at
end-of-message (you need to receive the message to see the Subject).
Something like the below might work (completely untested). Since you are
rejecting everyone else, you don't need to check the sender again in
LOCAL_RULE_0.
LOCAL_CONFIG
Kstorage macro
HSubject: $>Check_Subject
C{persistentMacros} {subj_exist}
C{ValidUsers} mailuser1 mailuser2
LOCAL_RULESETS
SCheck_Subject
R$* CRAZYBOY $* $: $(storage {subj_exist} $@ YES $) $&f $| $1 CRAZYBOY $2
R< $={ValidUsers} @ $* > $| $* $: $3
R$* $| $* $#error $: "553 Pls don't use the subject crazyboy"
LOCAL_RULE_0
R$* $: $1 $|$&{subj_exist} check macro
R$*$|YES $#esmtp $@mail.testext.com.$: $1 match, reroute
R$*$|$* $1 no match
--Per Hedeland
p...@hedeland.org
> LOCAL_RULE_0.
>
> LOCAL_CONFIG
> Kstorage macro
> HSubject: $>Check_Subject
> C{persistentMacros} {subj_exist}
> C{ValidUsers} mailuser1 mailuser2
>
> LOCAL_RULESETS
> SCheck_Subject
> R$* CRAZYBOY $* $: $(storage {subj_exist} $@ YES $) $&f $| $1 CRAZYBOY $2
> R< $={ValidUsers} @ $* > $| $* $: $3
> R$* $| $* $#error $: "553 Pls don't use the subject crazyboy"
>
> LOCAL_RULE_0
> R$* $: $1 $|$&{subj_exist} check macro
> R$*$|YES $#esmtp $...@mail.testext.com.$: $1 match, reroute
> R$*$|$* $1 no match
>
Regards
Biju
Untested sendmail rewrite rules failing to do what they're supposed to
do isn't "weird", it's expected.:-) Strange though, I seem to remember
that $&f should be exactly as given to sendmail, i.e. include the
surrounding <brackets> in case of SMTP, but that's not the case. More
robust rules (actually tested!):
LOCAL_RULESETS
SCheck_Subject
R$* CRAZYBOY $* $: $(storage {subj_exist} $@ YES $) $1 CRAZYBOY $2 $| $>canonify $&f
R$* $| $={ValidUsers} < @ $* > $: $1
R$* $| $* $#error $: "553 Pls don't use the subject crazyboy"
--Per Hedeland
p...@hedeland.org
Thanks a lot..That worked..
Now i got the mistakes i made when trying to debug the previous rule
set..
so i learned from the mistakes :) and this will help me in my further
tests
Anyway Thanks a lot for helping me in this regard
Cheers
Biju
I need a Some more help regarding the subject based mail forwarding
rule set.
Case 1:
---------------
My Ruleset is as follows. In this Rule Set i am also checking the
"message id" and "From" address of my outgoing mail other than the
"subject".
LOCAL_CONFIG
Kstorage macro
HSubject: $>Check_Subject
HMessage-ID: $>Check_MessageId
F{ValidUsers} /etc/mail/checkuser
C{persistentMacros} {sub_ex}
C{persistentMacros} {msg_ex}
LOCAL_RULESETS
SCheck_MessageId
R< $+ @ $* testint.com> $: $
(storage {msg_ex} $@ YES $) < $1 @ $2 testint.com >
SCheck_Subject
R$* crazy $* $: $
(storage {sub_ex} $@ YES $) $1 $2 $|$&{msg_ex}$|$>canonify $&f
R$*$|YES$|$={ValidUsers} < @ testext.com . > $: $1
R$*$|YES$|$*
$#error $@ 5.3.0 $: "553 Pls don't use the subject crazy"
LOCAL_RULE_0
R$*
$: $1 $|$&{sub_ex}$|
$&{msg_ex} check macro
R$*$|YES$|YES $#esmtp
$@[mail.testext.com.]$: $1 match,
reroute
R$*$|$*$|$*
$1
no match
My intention was as follows
1. If message id is "testint.com" and subject is the word "crazy"
and if it is from the list of "valid users" then the
message should be forwarded
2. If message id is "testint.com" and subject is the word "crazy"
and if it is NOT from the list of "valid users" then the
message should be rejected
3. If message id is "testint.com" and subject is "ANYTHING" and if
it IS/NOT from the list of "valid users" it should
NOT be Forwarded and should be delivered locally.
4. If message id is "Anything" and the subject is the word "crazy"
and if it IS/NOT from the list of "valid users" it
should NOT be Forwarded and should be delivered locally.
5. If message id is "Anything" and the subject is "Anything" and if
it IS/NOT from the list of "valid users" it should
NOT be Forwarded and should be delivered locally.
All the above (1 - 5) tests worked perfectly when i was using a
Mozilla Thunderbird as email client and Netscape as
Email Client.
In this case an error window popped up with the message "5.3.0 $:
"553 Pls don't use the subject crazy". (This was
in a pop up window, Not an error delivery failure email)
The problem happened when i tried all these tests using MS Outlook
as email client. Here the problem was with Test
No 2.
All other tests were successful. That is as per Test No 2, the
error/mail delivery failure email was not happening.
When trying Test No 2, I found that the mail was forwarded rather
than returning any mail delivery error.
Case 2:
--------------
So I tried another rule set just to test if "$#error" is returning
an error mail to the outlook. The rule set is mentioned below. This
rule set does force encryption if the mail is send from the client
without Encryption. (I got help from you 1.5 years back for this rule
set)
LOCAL_CONFIG
C{ClearTextIP}127.0.0.1
LOCAL_RULESETS
SLocal_check_rcpt
R$* $: $| $>canonify $1
R$| $* $: $&{client_addr}
R$@ $@ OK
R$* $: $&{alg_bits}
R$@ $#error $@ 5.7.1 $: "Encryption
Required"
R$* $@ OK
This worked perfectly with MS outlook. When i tried to send an email
without encryption, i got delivery failure error MAIL send from the
"System administrator" account with the message "Encryption
Required".
When i tried the same in Mozilla Thunderbird email client and Netscape
i got the same delivery error MAIL rather than a pop up window
( Note: In the first case (case 1) i got a pop up window with the
error message when using Thunderbird and
Netscape as email client)
Can you please help me to make "Case 1 - Test 2" successful when using
MS outlook as Email Client
I wrote this huge mail for explaining all that happened.
Thanks & Regards,
Biju