Postfix relay outgoing email messages based on message size

I know that I can choose different transport agents (different SMTP servers) for different mail accounts. However, how to deliver messages larger than 10 MB using local SMTP server and smaller messages using an external service (e.g. Google SMTP servers)?

Is there any message size based transport policies? How to edit them?

[more information]

The reason I want to do this since the external email provider I use for email delivery limits outgoing messages' size to a maximum of 10 MB each so I want to send those large messages using my own SMTP servers while all others using the external service.


Solution 1:

One way is to use the ClamAV milter. Scan outbound messages in the usual way, e.g.

smtpd_milters = unix:/var/run/clamav/clamav-milter
milter_default_action = accept

In the milter config, set

MaxFileSize 10M
AddHeader Replace

If the milter rejects the message, processing continues. But the X-Virus headers will be different. You can then use this header, e.g. in header_checks, for postfix to route accordingly.

Not entirely within postfix, so someone else might have a cleaner answer.