Encapsulate incomming bounce mail

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

Encapsulate incomming bounce mail

Dirk Stöcker
Hello,

in one project I'm sending a bunch of status mails to a number of
different recepients. From time some of them cannot be delivered
(address changes, server misconfigurations, employment changes, ...).

The bounces from the mail come back to my mail server and should go to a
contractor of us managing the e-mail addresses. Now I forward the mail to
an email on their mail server where it arrives, but later it gets lost
somewhere when internal distribution is done. Probably a mailinglist
dropping bounces or something alike.

I'd like to know if there is an easy way in my postfix instance to
encapsulate the bounce mails (or any email) I get into new mails of my own
containing the bounce and maybe a simple text like "E-Mail delivery issue
for ...", so it is no longer a normal bounce, but a normal email?

This task is done with a specific email address, so it should be easy to
extract the relevant mails.

Ciao
--
http://www.dstoecker.eu/ (PGP key available)
Reply | Threaded
Open this post in threaded view
|

Re: Encapsulate incomming bounce mail

Noel Jones-2
On 2/28/2017 1:47 PM, Dirk Stöcker wrote:
> Hello,
>
> in one project I'm sending a bunch of status mails to a number of
> different recepients. From time some of them cannot be delivered
> (address changes, server misconfigurations, employment changes, ...).
>
> The bounces from the mail come back to my mail server and should go
> to a contractor of us managing the e-mail addresses.

Stop there.  The mail envelope sender should direct bounces to the
party responsible, and they should deal with the mail directly.  Set
the envelope sender properly and don't use crappy workarounds.


> Now I forward
> the mail to an email on their mail server where it arrives, but
> later it gets lost somewhere when internal distribution is done.
> Probably a mailinglist dropping bounces or something alike.
>
> I'd like to know if there is an easy way in my postfix instance to
> encapsulate the bounce mails (or any email) I get into new mails of
> my own containing the bounce and maybe a simple text like "E-Mail
> delivery issue for ...", so it is no longer a normal bounce, but a
> normal email?

If you must do this, hold your nose and pipe the bounce to formail.
Or get a better provider.



  -- Noel Jones
Reply | Threaded
Open this post in threaded view
|

Re: Encapsulate incomming bounce mail

Dirk Stöcker
On Tue, 28 Feb 2017, Noel Jones wrote:

>> in one project I'm sending a bunch of status mails to a number of
>> different recepients. From time some of them cannot be delivered
>> (address changes, server misconfigurations, employment changes, ...).
>>
>> The bounces from the mail come back to my mail server and should go
>> to a contractor of us managing the e-mail addresses.
>
> Stop there.  The mail envelope sender should direct bounces to the
> party responsible, and they should deal with the mail directly.  Set
> the envelope sender properly and don't use crappy workarounds.

The mail is bounced to the server responsible for it - my mail server.

The "deal with the mail" is what I'm talking here, because I must inform
somebody else about the bounce. I'm searching a simple way to make the
bounce mail available in a form that it is not rejected by mailinglist
software with automatic bounce detection.

Currently I manually write a mail from time to time telling them about the
bouncing mails and the reasons, so they can update the database. It would
be MUCH easier when they simply could read the bounces themselves.

>> Now I forward the mail to an email on their mail server where it arrives, but
>> later it gets lost somewhere when internal distribution is done.
>> Probably a mailinglist dropping bounces or something alike.
>>
>> I'd like to know if there is an easy way in my postfix instance to
>> encapsulate the bounce mails (or any email) I get into new mails of
>> my own containing the bounce and maybe a simple text like "E-Mail
>> delivery issue for ...", so it is no longer a normal bounce, but a
>> normal email?
>
> If you must do this, hold your nose and pipe the bounce to formail.

Sorry, but that sentence does not help me to understand what needs to be
done at all.

> Or get a better provider.

What provider?

Ciao
--
http://www.dstoecker.eu/ (PGP key available)
Reply | Threaded
Open this post in threaded view
|

Re: Encapsulate incomming bounce mail

Dominic Raferd
On 4 March 2017 at 13:53, Dirk Stöcker <[hidden email]> wrote:

> On Tue, 28 Feb 2017, Noel Jones wrote:
>
>>> in one project I'm sending a bunch of status mails to a number of
>>> different recepients. From time some of them cannot be delivered
>>> (address changes, server misconfigurations, employment changes, ...).
>>>
>>> The bounces from the mail come back to my mail server and should go
>>> to a contractor of us managing the e-mail addresses.
>>
>>
>> Stop there.  The mail envelope sender should direct bounces to the
>> party responsible, and they should deal with the mail directly.  Set
>> the envelope sender properly and don't use crappy workarounds.
>
>
> The mail is bounced to the server responsible for it - my mail server.
>
> The "deal with the mail" is what I'm talking here, because I must inform
> somebody else about the bounce. I'm searching a simple way to make the
> bounce mail available in a form that it is not rejected by mailinglist
> software with automatic bounce detection.
>
> Currently I manually write a mail from time to time telling them about the
> bouncing mails and the reasons, so they can update the database. It would be
> MUCH easier when they simply could read the bounces themselves.
>
>>> Now I forward the mail to an email on their mail server where it arrives,
>>> but
>>> later it gets lost somewhere when internal distribution is done.
>>> Probably a mailinglist dropping bounces or something alike.
>>>
>>> I'd like to know if there is an easy way in my postfix instance to
>>> encapsulate the bounce mails (or any email) I get into new mails of
>>> my own containing the bounce and maybe a simple text like "E-Mail
>>> delivery issue for ...", so it is no longer a normal bounce, but a
>>> normal email?
>>
>>
>> If you must do this, hold your nose and pipe the bounce to formail.
>
>
> Sorry, but that sentence does not help me to understand what needs to be
> done at all.
>
>> Or get a better provider.
>
>
> What provider?

I have a similar situation. I wrote a script which spots the relevant
bounce message in the mail log, from this it extracts the queue-id and
uses this to identify the copy of the original email saved in the
temporary local mailbox (which saves all mails passing through the
server). It extracts this email from there and forwards it as an
attachment to the relevant person using s-nail, with an explanatory
cover message. The same approach might work for you.
Reply | Threaded
Open this post in threaded view
|

Re: Encapsulate incomming bounce mail

Viktor Dukhovni

> On Mar 4, 2017, at 9:56 AM, Dominic Raferd <[hidden email]> wrote:
>
> I have a similar situation. I wrote a script which spots the relevant
> bounce message in the mail log, from this it extracts the queue-id and
> uses this to identify the copy of the original email saved in the
> temporary local mailbox (which saves all mails passing through the
> server). It extracts this email from there and forwards it as an
> attachment to the relevant person using s-nail, with an explanatory
> cover message. The same approach might work for you.

This is much too complex.  To attach email message to another message,
just pipe it through the shell script below my signature.  This can
be used as part of a pipe(8) transport with the output submitted via
sendmail(1) for delivery.

--
        Viktor.

#! /bin/sh

sender=postmaster
rcpt=[hidden email]

cat <<EOF
From: $sender
To: $rcpt
Subject: Encapsulated bounce for your perusal
MIME-Version: 1.0
Content-Type: message/rfc822

EOF
cat



--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Encapsulate incomming bounce mail

Dominic Raferd
On 4 March 2017 at 17:55, Viktor Dukhovni <[hidden email]> wrote:

>
>> On Mar 4, 2017, at 9:56 AM, Dominic Raferd <[hidden email]> wrote:
>>
>> I have a similar situation. I wrote a script which spots the relevant
>> bounce message in the mail log, from this it extracts the queue-id and
>> uses this to identify the copy of the original email saved in the
>> temporary local mailbox (which saves all mails passing through the
>> server). It extracts this email from there and forwards it as an
>> attachment to the relevant person using s-nail, with an explanatory
>> cover message. The same approach might work for you.
>
> This is much too complex.  To attach email message to another message,
> just pipe it through the shell script below my signature.  This can
> be used as part of a pipe(8) transport with the output submitted via
> sendmail(1) for delivery.
>
> --
>         Viktor.
>
> #! /bin/sh
>
> sender=postmaster
> rcpt=[hidden email]
>
> cat <<EOF
> From: $sender
> To: $rcpt
> Subject: Encapsulated bounce for your perusal
> MIME-Version: 1.0
> Content-Type: message/rfc822
>
> EOF
> cat

That gets round the s-nail dependency (the final step in my script),
so thank you, but in my case (not so sure about OP) I need to recover,
and send on as encapsulated, the original email that has just been
bounced by the onward server, not the bounce message itself. Apart
from your change to this final step, is there a much easier approach
than mine in this situation?
Reply | Threaded
Open this post in threaded view
|

Re: Encapsulate incomming bounce mail

Dirk Stöcker
In reply to this post by Viktor Dukhovni
On Sat, 4 Mar 2017, Viktor Dukhovni wrote:

> This is much too complex.  To attach email message to another message,
> just pipe it through the shell script below my signature.  This can
> be used as part of a pipe(8) transport with the output submitted via
> sendmail(1) for delivery.

Thanks a lot. That's what I searched for and it is working fine ATM.

That's what I did:

In /etc/postfix/virtual the e-mail address directs to a name defined in
/etc/aliases:

caps: "|/etc/postfix/encapsulatemail [hidden email] [hidden email] [hidden email]"

The simple script is
----
#!/usr/bin/perl -w

use strict;

undef $/;

die if @ARGV < 2;
my $text = <STDIN>;
my $from = shift @ARGV;
my $sendmail = "/usr/sbin/sendmail -f $from ".join(" ", @ARGV);

open MAIL,"|-",$sendmail or die;

my $bounce = ($text =~ /delivery[ -](status|report)/i) ? "bounce " : "";
my $subject = ($text =~ /Subject: (.*)/) ? " [$1]" : "";

print MAIL "From: $from\n"
     . "To: ".join(",",@ARGV)."\n"
     . "Subject: Encapsulated ${bounce}mail$subject\n"
     . "MIME-Version: 1.0\n"
     . "Message-ID: <".(time)."_${$}\@encapsulatemail>\n"
     . "Content-Type: message/rfc822\n\n$text";
----

As long as nobody starts spamming that addresses this solution will be
fine. :-)

Security note: The [hidden email] should not go back to the original input
address...

Ciao
--
http://www.dstoecker.eu/ (PGP key available)