VERP and perl postfix not working

579 views Asked by At

So I have a script that I'm trying to get VERP running correctly on. It's using MIME::Lite and postfix as the mail server. Here is the code:

use strict;
use MIME::Lite;
use LWP::Simple;
use Mail::Verp;

my $email = '[email protected]';
Mail::Verp->separator('+');
my $verp_email = Mail::Verp->encode('[email protected]', $email);
my $content = '<html><body>Hi!</body></html>';
my $msg = MIME::Lite->new(
    Subject => 'Hi',
    From => '[email protected]',
    To => $email,
    'Return-Path' => $verp_email,
    Type => 'text/html',
    Data => $content
);
$msg->send('smtp', 'XXX.XXX.XXX.XXX');

When the message is bounced postfix isn't routing it to the [email protected] email inbox. How do I route the message so that the sender of the bounce is the $verp_email value?

I'm trying to create a log of all bounced emails with the email addresses included so that it can then be sent to a file or a database.

If anyone can point me in the right direction with this I would be extremely appreciative. Thanks.

2

There are 2 answers

0
Jacques On

The question is a bit old, but hopefully my answer will contribute to someone who find this while googling. I had the same problem, and the root cause is that you must use "MAIL FROM: " during the smtp exchange with the target server. Setting the return-path in the MIME::Header gets overwriten by the smtp server itself precisely based on the MAIL FROM smtp command. So you can have a Mail envelope containing From: [email protected] but make sure the smtp MAIL FROM uses $verp_email For example, this is what I have done:

my $msg = MIME::Entity->build(
    'Return-Path'   => '[email protected]',
    'From'      => '[email protected]',
    'To'        => '[email protected]',
    'Subject'   => $subject,
    'Errors-To' => '[email protected]'
);
## Then some more handling with MIME::Entity
## and finally send it over smtp

my @rcpt = $msg->smtpsend(
    ## Make it verbose for debugging
    'Debug'     => DEBUG,
    'Hello'     => 'mx1.my-server.com',
    'Host'      => 'mx.user-domain.com,
    'MailFrom'  => '[email protected]',
    'To'        => '[email protected]',
    'Port'      => 25,
);
0
tripleee On

Return-Path is not the correct place for the VERP address, and will be ignored and/or overridden. You need to put it as the actual, honest to $dmr, real SMTP envelope sender (MAIL FROM:<>) address.