VERP and perl postfix not working - perl

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 = 'someuser#somesite.com';
Mail::Verp->separator('+');
my $verp_email = Mail::Verp->encode('root#somesite.net', $email);
my $content = '<html><body>Hi!</body></html>';
my $msg = MIME::Lite->new(
Subject => 'Hi',
From => 'root#somesite.net',
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 root#somesite.net 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.

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.

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: root#somesite.net 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' => 'bounce+user=user-domain.com#my-server.com',
'From' => 'admin#my-server.com',
'To' => 'user#user-domain.com',
'Subject' => $subject,
'Errors-To' => 'bounce+user=user-domain.com#my-server.com'
);
## 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' => 'bounce+user=user-domain.com#my-server.com',
'To' => 'user#user-domain.com',
'Port' => 25,
);

Related

Perl mail attachment file size limit

I am using MIME::Lite module to send attachments in email and everything works fine until I realized attachment larger than 15mb cannot be sent successfully. Any suggestion on other module which not having size limit?
You should consider using a different module because that's what the author recommends (try Email::MIME, MIME::Entity or Email::Sender). However, it's not the module that determines the attachment size restriction.
The size limit you're seeing is set by your SMTP server. If you're not explicitly configuring your SMTP server you're using your local service which might differ depending on your OS. You're probably using sendmail or postfix.
See size limit in postfix
postconf | grep message_size_limit
See size limit in sendmail
grep MaxMessageSize /etc/mail/sendmail.cf
If you're using an external SMTP server they usually have their own size limits. Google has a 25MB size limit for their SMTP server smtp.gmail.com. If that's sufficient for you you could send your mail via Google by authenticating.
$msg->send(
'smtp', 'smtp.gmail.com',
Port => 465,
SSL => 1,
AuthUser => $user,
AuthPass => $password,
);
EDIT: I had some issues using MIME::Lite to work properly with Gmail SMTP server so I here's an example on how to use gmail.smtp.com with an alternative pacakge.
#!/usr/bin/env perl
use warnings;
use strict;
use Email::Sender::Simple qw( sendmail );
use Email::Sender::Transport::SMTP;
use Email::Simple;
my $user = 'username#gmail.com';
my $password = 'app-password';
my $host = 'smtp.gmail.com';
my $port = 465;
my $transport = Email::Sender::Transport::SMTP->new(
{
host => $host,
port => $port,
ssl => 1,
sasl_username => $user,
sasl_password => $password,
}
);
my $email = Email::Simple->create(
header => [
To => 'someone#example.com',
From => 'me#localhost',
Subject => 'Hello...',
],
body => "World!\n",
);
sendmail( $email, { transport => $transport } );

People in cc are not receiving the mail using MIME::Lite api

Please find below my code snippet that send a mail to person and his friend in cc.
In the cc list I also have a DL.
use MIME::Lite;
$to = 'ABC#DOMAIN1.com';
$from = 'MAILER#DOMAIN2.com';
$subject = 'How are you doing';
$message = 'This is test email sent by Perl Script';
my #cc=('XYZ#DOMAIN2.com','DL#DOMAIN2.com');
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc =>\#cc,
Subject => $subject,
Data => $message
);
$msg->send('smtp','smtpserver', Timeout => 60 );
print "Email Sent Successfully\n";
The problem is the person and DL is cc are not receiving the mails.
Is there any log in the api MIME::Lite where I can check what is the error(if any)Or what do you think the problem can be?
Perhaps you want to take a closer look at the documentation for MIME::Lite. Here's the first example from the synopsis.
use MIME::Lite;
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From => 'me#myhost.com',
To => 'you#yourhost.com',
Cc => 'some#other.com, some#more.com',
Subject => 'Helloooooo, nurse!',
Type => 'image/gif',
Encoding => 'base64',
Path => 'hellonurse.gif'
);
$msg->send; # send via default
The Cc parameter here is sent as a text string containing comma-separated email addresses. You are passing in a reference to an array of email addresses.

MIME::Lite - Mail to multiple recipients [duplicate]

Please find below my code snippet that send a mail to person and his friend in cc.
In the cc list I also have a DL.
use MIME::Lite;
$to = 'ABC#DOMAIN1.com';
$from = 'MAILER#DOMAIN2.com';
$subject = 'How are you doing';
$message = 'This is test email sent by Perl Script';
my #cc=('XYZ#DOMAIN2.com','DL#DOMAIN2.com');
$msg = MIME::Lite->new(
From => $from,
To => $to,
Cc =>\#cc,
Subject => $subject,
Data => $message
);
$msg->send('smtp','smtpserver', Timeout => 60 );
print "Email Sent Successfully\n";
The problem is the person and DL is cc are not receiving the mails.
Is there any log in the api MIME::Lite where I can check what is the error(if any)Or what do you think the problem can be?
Perhaps you want to take a closer look at the documentation for MIME::Lite. Here's the first example from the synopsis.
use MIME::Lite;
### Create a new single-part message, to send a GIF file:
$msg = MIME::Lite->new(
From => 'me#myhost.com',
To => 'you#yourhost.com',
Cc => 'some#other.com, some#more.com',
Subject => 'Helloooooo, nurse!',
Type => 'image/gif',
Encoding => 'base64',
Path => 'hellonurse.gif'
);
$msg->send; # send via default
The Cc parameter here is sent as a text string containing comma-separated email addresses. You are passing in a reference to an array of email addresses.

MIME::Lite and the Message-ID

When using MIME::Lite is there a way to get the Message-ID assigned by the MTA when the message is accepted? Here's my code snippet.
$msg = MIME::Lite->new(
From => $from_address,
To => $recipient,
Bcc => $recipient,
Subject => $subject,
Type => 'text/html',
Data => $text);
$status = $msg->send();
I've tried setting Debug=>1 in the $msg->send command but $status does not contain the Message-ID nor does the debug output have it.
Thanks,
Rick
No. If you want to know the message ID, you can try setting one yourself, and then checking if your MTA uses it, or overwrites it.

How do I send an Email with no "to" address using Mail::Sender?

Is it possible to send an Email with only cc or bcc recipients using Mail::Sender? When I try to send an Email without a "to" address, I get the expected return code:
-8 = argument $to empty
Using an empty string '' in the "to" field does not work. Using a space works like a charm.
use Mail::Sender;
my $sender = Mail::Sender->new();
my $mail = {
smtp => 'mailserver',
from => 'example#example.com',
to => ' ',
bcc => 'example#example.com',
subject => 'test',
ctype => 'text/plain; charset=utf-8',
skip_bad_recipients => 1,
msg => 'test'
};
my $ret = $sender->MailMsg($mail);
print $ret;
Does the fake_to parameter work:
fake_to
=> the recipient's address that will be shown in headers. If not specified we use the value of "to".
If the list of addresses you want to send your message to is long or if you do not want the recipients to see each other's address set the fake_to parameter to some informative, yet bogus, address or to the address of your mailing/distribution list.
http://metacpan.org/pod/Mail::Sender
Looking at the source, it seems you'd still need to set the to parameter to something. Perhaps " " would do the trick?
Have you tried using '' ?