On Sat, Jan 16, 2021 at 08:14:34AM +0000, Alexander wrote:

> My goal is to conditionally select the relayhost based on the total size 
> of the outgoing message. The rationale is that I'm using Amazon AWS SES 
> for the most part. Alas, SES only accepts messages up to 10 MB in size 
> (this includes images and attachments that are part of the message), and 
> when the outgoing message exceeds that size, it will be bounced.
> 
> Any tips for filters or tools that would help me define another 
> relayhost based on the outgoing message size would be greatly 
> appreciated!

Since the queue manager has no mechanism for size-dependent selection of
a default transport (with the help of trivial-rewrite), the only way
handle this deterministically in Postfix is to shunt large messages into
a separate instance, which can be done in a number of ways, but is not
particularly simple or elegant.

The simplest is perhaps to allow the message to route to AWS, where it
would typically rejected in response to "MAIL FROM" when Postfix
announces the message size, and to map that response to a tempfail, at
which point the message would go the SMTP fallback relay for the
transport, but this can be complex if amazon publishes many IP addresses
for their submission service, since Postfix would try those first and
may give up after a small number of connections.  You'd therefore need
to also ensure that the AWS relay resolves to just 1 IP address.

That could be done with Python hooks in unbound, or a static IP
(bypassing live DNS) that's updated out of band.

If you want to take the second instance route, then it may be simplest
to place large messages on hold, and within the same filesystem, move
messages from the hold queue to the incoming queue of the second
instance.  Alternatively, an SMTP content_filter could dynamically
choose the reinjection port based on message size, but you'd need
to implement such an SMTP proxy.

Finally, you could always try Exim.  For sufficiently exotic
requirements, though I'm generally loathe to recomment a complex
monolithic MTA with a spotty security track record, it does offer a lot
more conditional logic in its mail processing pipeline.

You might even use Exim as a content_filter for Postfix, and have
Postfix ultimately deliver the outbound message, with Exim routing the
message to one of two Postfix instances.  Though it is rather overkill
if all you want is a size-dependent SMTP switch.

-- 
    Viktor.

Reply via email to