Relay via command-line MTA instead of 'relayhost' SMTP server?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
I'm trying to figure out how to set up an SMTP server that accepts
incoming mail and relays it by invoking a command-line MTA
(e.g. /usr/bin/sendmail or equivalent) instead of connecting to a
'smarthost' SMTP server.

Can Postfix do that?

--
Grant Edwards               grant.b.edwards        Yow! Did an Italian CRANE
                                  at               OPERATOR just experience
                              gmail.com            uninhibited sensations in
                                                   a MALIBU HOT TUB?

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Viktor Dukhovni


> On Jan 19, 2018, at 1:15 PM, Grant Edwards <[hidden email]> wrote:
>
> I'm trying to figure out how to set up an SMTP server that accepts
> incoming mail and relays it by invoking a command-line MTA
> (e.g. /usr/bin/sendmail or equivalent) instead of connecting to a
> 'smarthost' SMTP server.

That'd be magic.  How exactly is the command-line MTA supposed to
get the mail "relayed" without connecting to a remote host?

> Can Postfix do that?

It is far from clear what you have in mind.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
On 2018-01-19, Viktor Dukhovni <[hidden email]> wrote:

>
>
>> On Jan 19, 2018, at 1:15 PM, Grant Edwards <[hidden email]> wrote:
>>
>> I'm trying to figure out how to set up an SMTP server that accepts
>> incoming mail and relays it by invoking a command-line MTA
>> (e.g. /usr/bin/sendmail or equivalent) instead of connecting to a
>> 'smarthost' SMTP server.
>
> That'd be magic.  How exactly is the command-line MTA supposed to
> get the mail "relayed" without connecting to a remote host?

Let's not worry about how the command-line MTA works.  It has the same
usage as /usr/bin/sendmail and it works.  What I am asking for is an
SMTP relay server that will relay incoming my by invoking it.

>> Can Postfix do that?
>
> It is far from clear what you have in mind.

I'm asking if Postfix can relay mail, but instead of Postifix sending
relayed mail by opening an SMTP connection to a relayhost, I want
Postfix to invoke a command line MTA that I specify.  That command
line MTA has the same API as /usr/bin/sendmail.

--
Grant Edwards               grant.b.edwards        Yow! I've got a COUSIN
                                  at               who works in the GARMENT
                              gmail.com            DISTRICT ...

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Ralph Seichter
On 19.01.18 19:45, Grant Edwards wrote:

> Let's not worry about how the command-line MTA works. It has the same
> usage as /usr/bin/sendmail and it works. What I am asking for is an
> SMTP relay server that will relay incoming my by invoking it.

"Relaying" implies passing mail to another server via network. Also, I
have no idea why you would not want Postfix to do its job, but anyway:
Postfix can pass incoming mail to a binary during local delivery. You
can for example set up an alias (http://www.postfix.org/aliases.5.html):

  # /etc/aliases
  mybinary: |/path/to/binary

Make sure to configure 'alias_database' accordingly. Sending mail to
[hidden email] should then be enough to invoke the binary
(with default values for 'mydestination').

-Ralph
Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Viktor Dukhovni
In reply to this post by Grant Edwards
On Fri, Jan 19, 2018 at 06:45:29PM +0000, Grant Edwards wrote:

> > That'd be magic.  How exactly is the command-line MTA supposed to
> > get the mail "relayed" without connecting to a remote host?
>
> Let's not worry about how the command-line MTA works.  It has the same
> usage as /usr/bin/sendmail and it works.  What I am asking for is an
> SMTP relay server that will relay incoming my by invoking it.

This is much less efficient than SMTP, so don't expect stellar
performance.  But sure, Postfix can deliver via an external
program.

   http://www.postfix.org/pipe.8.html

    main.cf:
        default_transport = mypipe:dummy

    master.cf:
        mypipe    unix  -       n       n       -       -       pipe
          null_sender_replacement=
          flags=q.
          user=nobody
          argv=/usr/local/sbin/myscript -f $sender -- $recipient

Note that you to *either* include "." in the flags, or include "-i"
in argv if the submission program does "SMTP transparency" (interprets
leading dots on lines) by default.  Run the script as some dedicated
user instead of "nobody" if possible but NOT as "postfix".

--
        Viktor.
Reply | Threaded
Open this post in threaded view
|

RE: Relay via command-line MTA instead of 'relayhost' SMTP server?

Kevin Miller
In reply to this post by Grant Edwards
If I understand you right, take a look at the transport file in /etc/postfix.
My postfix transport table has entries similar to this:
  example.com         smtp:[192.168.1.96]

Our mx host(s) accept mail for our domains, then automatically relays it to an internal server which our users access.  Is that what you're after?

...Kevin
--
Kevin Miller
Network/email Administrator, CBJ MIS Dept.
155 South Seward Street
Juneau, Alaska 99801
Phone: (907) 586-0242, Fax: (907) 586-4588 Registered Linux User No: 307357


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Grant Edwards
Sent: Friday, January 19, 2018 9:16 AM
To: [hidden email]
Subject: Relay via command-line MTA instead of 'relayhost' SMTP server?

I'm trying to figure out how to set up an SMTP server that accepts incoming mail and relays it by invoking a command-line MTA (e.g. /usr/bin/sendmail or equivalent) instead of connecting to a 'smarthost' SMTP server.

Can Postfix do that?

--
Grant Edwards               grant.b.edwards        Yow! Did an Italian CRANE
                                  at               OPERATOR just experience
                              gmail.com            uninhibited sensations in
                                                   a MALIBU HOT TUB?

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Wietse Venema
In reply to this post by Grant Edwards
Grant Edwards:
> I'm trying to figure out how to set up an SMTP server that accepts
> incoming mail and relays it by invoking a command-line MTA
> (e.g. /usr/bin/sendmail or equivalent) instead of connecting to a
> 'smarthost' SMTP server.
>
> Can Postfix do that?

Sure. Just set up the TIS toolkit smap program as an SMTP receiver,
and have smapd hand off the message to /usr/sbin/sendmail.

https://docstore.mik.ua/orelly/networking/puis/ch22_02.htm

I ran Sendmail like that about 20 years ago, before I switched
to Postfix.

But, since Postfix already solves the problems that smap/smapd
were designed to solve, I don't see why one would want to do
that with the Postfix sendmail command.

        Wietse
Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
In reply to this post by Ralph Seichter
On 2018-01-19, Ralph Seichter <[hidden email]> wrote:
> On 19.01.18 19:45, Grant Edwards wrote:
>
>> Let's not worry about how the command-line MTA works. It has the same
>> usage as /usr/bin/sendmail and it works. What I am asking for is an
>> SMTP relay server that will relay incoming my by invoking it.
>
> "Relaying" implies passing mail to another server via network.

Yes, that's what the command-line MTA utility does.

> Also, I have no idea why you would not want Postfix to do its job,

Becuase postfix doesn't implement the protocols used by that
command-line utility to transfer the mail to another server via the
network.

> but anyway: Postfix can pass incoming mail to a binary during local
> delivery.

And it will do 'local delivery' for any and all recipient addresses?
There are no local email users.

> You can for example set up an alias
> (http://www.postfix.org/aliases.5.html):

But that says it's for local recipients.  There are no local
recipients.

>   # /etc/aliases
>   mybinary: |/path/to/binary

And that binary will be passed command-line options and arguments
compatible with /usr/bin/sendmail?

> Make sure to configure 'alias_database' accordingly. Sending mail to
> [hidden email] should then be enough to invoke the binary
> (with default values for 'mydestination').

--
Grant Edwards               grant.b.edwards        Yow! We have DIFFERENT
                                  at               amounts of HAIR --
                              gmail.com            

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Viktor Dukhovni
In reply to this post by Ralph Seichter
On Fri, Jan 19, 2018 at 08:05:49PM +0100, Ralph Seichter wrote:

> "Relaying" implies passing mail to another server via network. Also, I
> have no idea why you would not want Postfix to do its job, but anyway:
> Postfix can pass incoming mail to a binary during local delivery. You
> can for example set up an alias (http://www.postfix.org/aliases.5.html):
>
>   # /etc/aliases
>   mybinary: |/path/to/binary

No, that's not the right mechanism here.  A pipe(8) transport is
the more sensible approach.

--
        Viktor.
Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Ralph Seichter
On 19.01.18 20:20, Viktor Dukhovni wrote:

> A pipe(8) transport is the more sensible approach.

Given the additional information posted by the OP in the meantime,
I agree.

-Ralph
Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
In reply to this post by Viktor Dukhovni
On 2018-01-19, Viktor Dukhovni <[hidden email]> wrote:

> On Fri, Jan 19, 2018 at 06:45:29PM +0000, Grant Edwards wrote:
>
>> > That'd be magic.  How exactly is the command-line MTA supposed to
>> > get the mail "relayed" without connecting to a remote host?
>>
>> Let's not worry about how the command-line MTA works.  It has the same
>> usage as /usr/bin/sendmail and it works.  What I am asking for is an
>> SMTP relay server that will relay incoming my by invoking it.
>
> This is much less efficient than SMTP, so don't expect stellar
> performance.

No worries, I need to handle a couple messages per week.

> But sure, Postfix can deliver via an external program.
>
>    http://www.postfix.org/pipe.8.html
>
>     main.cf:
> default_transport = mypipe:dummy
>
>     master.cf:
> mypipe    unix  -       n       n       -       -       pipe
>  null_sender_replacement=
>  flags=q.
>  user=nobody
>  argv=/usr/local/sbin/myscript -f $sender -- $recipient
>
> Note that you to *either* include "." in the flags, or include "-i"
> in argv if the submission program does "SMTP transparency" (interprets
> leading dots on lines) by default.  Run the script as some dedicated
> user instead of "nobody" if possible but NOT as "postfix".

Ah!  That does look like what I've been trying to find.

Now that I know what to google for, this looks like it's close to what
I'm trying to do:

  https://serverfault.com/questions/258469/how-to-configure-postfix-to-pipe-all-incoming-email-to-a-script

But, that example is set up so the pipe is only invoked for a
particular domain.

Thanks!

--
Grant Edwards               grant.b.edwards        Yow! I selected E5 ... but
                                  at               I didn't hear "Sam the Sham
                              gmail.com            and the Pharoahs"!

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Matus UHLAR - fantomas
In reply to this post by Grant Edwards
On 19.01.18 19:15, Grant Edwards wrote:
>Becuase postfix doesn't implement the protocols used by that
>command-line utility to transfer the mail to another server via the
>network.

which one is that?


--
Matus UHLAR - fantomas, [hidden email] ; http://www.fantomas.sk/
Warning: I wish NOT to receive e-mail advertising to this address.
Varovanie: na tuto adresu chcem NEDOSTAVAT akukolvek reklamnu postu.
"Where do you want to go to die?" [Microsoft]
Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
On 2018-01-19, Matus UHLAR - fantomas <[hidden email]> wrote:
> On 19.01.18 19:15, Grant Edwards wrote:
>>Becuase postfix doesn't implement the protocols used by that
>>command-line utility to transfer the mail to another server via the
>>network.
>
> which one is that?

It does some stuff via the ssh-2 protocol.

--
Grant Edwards               grant.b.edwards        Yow! I wish I was on a
                                  at               Cincinnati street corner
                              gmail.com            holding a clean dog!

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Viktor Dukhovni


> On Jan 19, 2018, at 5:48 PM, Grant Edwards <[hidden email]> wrote:
>
>
> It does some stuff via the ssh-2 protocol.

Note that with my suggestion to override "default_transport" not only the
original messages, but also any bounces or delay notifications go out via
the same transport.  If the destination is responsible for only a limited
number of domains, it is better to use explicit transport entries for those,
and let bounces, ... go back out via SMTP.

Do also make sure to get the dot-stuffing (SMTP transparency) 100% right.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
On 2018-01-19, Viktor Dukhovni <[hidden email]> wrote:

>
>
>> On Jan 19, 2018, at 5:48 PM, Grant Edwards <[hidden email]> wrote:
>>
>>
>> It does some stuff via the ssh-2 protocol.
>
> Note that with my suggestion to override "default_transport" not only the
> original messages, but also any bounces or delay notifications go out via
> the same transport.

Ah. That's a problem.  I would need the special pipe transport to be
used for everything _except_ bounce/delay notifications.

> If the destination is responsible for only a limited number of
> domains,

No, it should be responsible for everything except bounce/delay
notifications.  If the default_transport gets broken (as it probably
will periodically), then using it for bounce notifications isn't going
to work.

> it is better to use explicit transport entries for those, and let
> bounces, ... go back out via SMTP.
>
> Do also make sure to get the dot-stuffing (SMTP transparency) 100%
> right.

--
Grant Edwards               grant.b.edwards        Yow! Vote for ME -- I'm
                                  at               well-tapered, half-cocked,
                              gmail.com            ill-conceived and
                                                   TAX-DEFERRED!

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Viktor Dukhovni


> On Jan 19, 2018, at 6:10 PM, Grant Edwards <[hidden email]> wrote:
>
>> Note that with my suggestion to override "default_transport" not only the
>> original messages, but also any bounces or delay notifications go out via
>> the same transport.
>
> Ah. That's a problem.  I would need the special pipe transport to be
> used for everything _except_ bounce/delay notifications.

You have two possible solutions:

1.  Use sender_dependent_default_transport_maps with regexp tables
    to direct all non-empty sender domains to the special outbound
    transport.

2.  Use "content_filter" to direct all email via the outbound transport,
    with "default_transport = smtp" as usuaul, as internally generated
    messages are not subject to content_filter.

The difference between 1 and 2 is that 1 will have specially handling
for all email with a non-emtpy sender address, while 2 will have
special handling for all email that originates outside of Postfix.
   
--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Relay via command-line MTA instead of 'relayhost' SMTP server?

Grant Edwards
On 2018-01-20, Viktor Dukhovni <[hidden email]> wrote:

>> On Jan 19, 2018, at 6:10 PM, Grant Edwards <[hidden email]> wrote:
>>
>>> Note that with my suggestion to override "default_transport" not only the
>>> original messages, but also any bounces or delay notifications go out via
>>> the same transport.
>>
>> Ah. That's a problem.  I would need the special pipe transport to be
>> used for everything _except_ bounce/delay notifications.
>
> You have two possible solutions:
>
> 1.  Use sender_dependent_default_transport_maps with regexp tables
>     to direct all non-empty sender domains to the special outbound
>     transport.
>
> 2.  Use "content_filter" to direct all email via the outbound transport,
>     with "default_transport = smtp" as usuaul, as internally generated
>     messages are not subject to content_filter.
>
> The difference between 1 and 2 is that 1 will have specially handling
> for all email with a non-emtpy sender address, while 2 will have
> special handling for all email that originates outside of Postfix.

Cool, thanks for the clues.

--
Grant