Hi Viktor, Thanks again. Just another question. Should I use it as content filter?
Thanks Carlo > On 21 Mar 2017, at 18:38, Viktor Dukhovni <postfix-us...@dukhovni.org> wrote: > > >> On Mar 21, 2017, at 12:46 PM, Carlo Poggiarelli <c.poggiare...@gmail.com> >> wrote: >> >> An exchange server sends to postfix an email with multiple addresses >> in the to field. This message should be sent to an sms gateway that >> accepts one address only in the to field. If ti receives an email with >> multiple addresses, it sends the sms message to the first addresses in >> the to field only discarding the others. > > The SMS gateway is rather badly implemented. Email must not be routed > based on the content of the To: or Cc: headers. However, if you cannot > repair or replace the SMS gateway, it is possible to work around this in > Postfix. > > main.cf: > indexed = ${default_database_type}:${config_directory}/ > transport = ${indexed}transport > sms_destination_recipient_limit = 1 > sms_destination_concurrency_limit = 2 > > transport: > sms.example sms > sms.invalid realsms > > master.cf: > sms unix - n n - 20 pipe > flags=Dq user=nobody null_sender= argv=/some/script ${sender} ${user} > realsms ... > > /some/script: > #! /bin/sh > ( > printf "From: %s\nTo: %s\n" "$@" > perl -ne ' > BEGIN { $header = 1; $buf = "" } > sub doheader { > print $buf if ($buf ne "" && $buf !~ m{^to:}i); > $buf = ""; > } > s/\r+$// > if (/^$/) { header(); $header = 0; } > if (! $header) { print; next; } > doheader() if (m{^\S}); > $buf .= $_; > ' > ) | sendmail -f "$1" -- "$2@sms.invalid" > > It remains to define a suitable "realsms" transport. If > that's SMTP, you may also need to apply smtp_generic_maps > to rewrite the envelope recipient back from "@sms.invalid" > to "@sms.example". (Note "sms.example" is not the real > domain to use, replace as appropriate). > > Keep in mind you may need to debug and fine-tune this, it is > not a tested or necessarily complete recipe. > > -- > Viktor. >