Rule That Applies to Outbound Messages Only

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
Post Reply
mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Rule That Applies to Outbound Messages Only

Post by mikedibella » 2020-12-15 20:52

My hMailServer is a primarily a bridgehead. I have a series of Routes defined for inbound domains, and I use a smart relay for outbound messages.

I have some use cases where I'd like to send outbound email though an alternate smart relay, and I've defined a Route to configure the target host parameters for that relay.

I'd like to use a Global Rule with a Send via Route Action to select the messages to be processed though this outbound Route, but I'm concerned that the Rule Criteria will include some messages that are inbound and I still want those messages to be handled by domain-based (as opposed to Rule-based) Routes.

All incoming mail arrives on port 25 unauthenticated and all outgoing mail arrives on port 587 and is authenticated.

Any ideas how I can use Rule Condition to positively identify outbound mail?

palinka
Senior user
Senior user
Posts: 2475
Joined: 2017-09-12 17:57

Re: Rule That Applies to Outbound Messages Only

Post by palinka » 2020-12-16 00:57

A shot in the dark:

Add a header value when user is authenticated AND on port 587, then make your rule check the header for header.

User avatar
SorenR
Senior user
Senior user
Posts: 4195
Joined: 2006-08-21 15:38
Location: Denmark

Re: Rule That Applies to Outbound Messages Only

Post by SorenR » 2020-12-16 01:46

Hmmm.... I presume only clients authenticate on this server.

Criteria:
Custom header field -> "Received"
- Search type -> Regular expression -> "(?i:^.*(ESMTPSA|ESMTPA).*$)"
AND
Predefined field -> "To"
- Search type -> Contains -> "Santa"

Action:
Send using route -> "Northpole"

Note:
Referencing the "Received:" header will ALLWAYS point to the topmost "Received:" header in the raw email.
ESMTPSA = Extended SMTP SSL/TLS Authenticated
ESMTPA = Extended SMTP Authenticated
SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

mikedibella
Senior user
Senior user
Posts: 390
Joined: 2016-12-08 02:21

Re: Rule That Applies to Outbound Messages Only

Post by mikedibella » 2020-12-16 02:04

SorenR wrote:
2020-12-16 01:46
- Search type -> Regular expression -> "(?i:^.*(ESMTPSA|ESMTPA).*$)"
Clever. I prefer this approach to adding a custom header in OnAcceptMessage. I will give it a try. TYVM all.

User avatar
SorenR
Senior user
Senior user
Posts: 4195
Joined: 2006-08-21 15:38
Location: Denmark

Re: Rule That Applies to Outbound Messages Only

Post by SorenR » 2020-12-16 02:24

mikedibella wrote:
2020-12-16 02:04
SorenR wrote:
2020-12-16 01:46
- Search type -> Regular expression -> "(?i:^.*(ESMTPSA|ESMTPA).*$)"
Clever. I prefer this approach to adding a custom header in OnAcceptMessage. I will give it a try. TYVM all.
I use it here..

Code: Select all

Sub OnDeliveryStart(oMessage)

    'Local:  Received: from computer.genious (sorens_acer [192.168.0.61]) by mx.acme.inc with ESMTPSA (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256) ; Mon, 16 Nov 2020 21:24:26 +0100
    'Remote: Received: from 66-220-155-155.mail-mail.facebook.com (66-220-155-155.mail-mail.facebook.com [66.220.155.155]) by mx.lolle.org with ESMTPS (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256) ; Thu, 13 Aug 2020 21:46:29 +0200

    Dim strReceived
    strReceived = oMessage.HeaderValue("Received")
    If InStr(strReceived, "ESMTPSA") or InStr(strReceived, "ESMTPA") Then
        oMessage.HeaderValue("Received") = Mid(strReceived, InStr(strReceived, "by "))
        oMessage.Save
    End If
End Sub
This is now anonymous -> Received: by mx.acme.inc with ESMTPSA (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256) ; Mon, 16 Nov 2020 21:24:26 +0100

:mrgreen:
SørenR.

Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.

Post Reply