Perl mail attachment file size limit - perl

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 } );

Related

How to use Email::Mime with sendmail

I am trying to send HTML email using a script. I will have to use native unix things and Email::Mime since those are the only thing I found installed in the box i am stuck with. I am creating a Email::Mime message and sending it to sendmail.
But i keep getting Error: No recipient addresses found in header
I have seen other RUBY scripts using sendmail so that works for this box.
Can someone help me with what I might be doing wrong in the below snippet?
sub send_mail(){
use MIME::QuotedPrint;
use HTML::Entities;
use IO::All;
use Email::MIME;
# multipart message
my #parts = (
Email::MIME->create(
attributes => {
content_type => "text/html",
disposition => "attachment",
encoding => "quoted-printable",
charset => "US-ASCII",
},
body_str => "Hello there!",
),
);
my $email = Email::MIME->create(
header_str => [
To => 'abc#xxx.com',
From => 'abc#xxx.com',
Subject => "Test Email",
],
parts => [#parts],
);
# die $email->as_string;
# die YAML::XS::Dump(\%mail);
open(MAIL, "|/usr/sbin/sendmail -t");
print MAIL $email;
close (MAIL);
}
Thanks in advance.
print MAIL $email;
should be
print MAIL $email->as_string;
First of all, if your E-Mail server requires authentication (which most do of course), you need to specify a SMTP session:
$transport = EMail::Sender::Transport::SMTP::Persistent->new({
# host, port, ssl, etc
})
Furthermore, I think you don't actually need to create the content as an own MIME-content.
I did use something similar to this in my own work:
$email = Email::MIME->Create(
header_str => [ ... ],
body_str => $message,
attributes => {
charset => 'UTF-8',
encoding => 'base64',
content_type => 'text/html',
}
)
After sending your mail via sendmail($email, { transport => $transport }), you need to close the session through $transport->disconnect.
For your application you might to adapt several things like the actual sending protocol (if different from SMTP) or the attributes hash contents.

perl sending email works on one system but not another

I have a simple sending email perl code.
use strict;
use warnings;
use Time::Format;
use Email::MIME;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP;
my $message = Email::MIME->create(
header_str => [
From => 'me#provider.com',
To => 'me#provider.com',
Subject => 'test',
],
attributes => {
encoding => 'quoted-printable',
charset => 'ISO-8859-1',
},
body_str => 'stefy test',
);
my $transport = Email::Sender::Transport::SMTP->new({
host => 'my.server.smtp',
port => 25,
});
sendmail($message, { transport => $transport });
I can it run with success in one system but not another.
Windows 7 professional -> success
Window Server 2008 -> failure
this is the exception I get:
unable to establish SMTP connection to my.server.smtp port 25
Trace begun at D:\strawberryperl\perl\site\lib\Email\Sender\Transport\SMTP.pm line 193 Email::Sender::Transport::SMTP::_throw('Email::Sender::Transport::SMTP=HASH(0x38
0fef8)', 'unable to establish SMTP connection to my.server.smtp port 25') called at D:\strawberryperl\perl\site\lib\Email\Sender\Transport\SMTP.pm line 143
Any idea ?
thank you
update of the perl version fixed the problem.
This is perl 5, version 26, subversion 2 (v5.26.2) built for MSWin32-x64-multi-t
hread

Does Perl module Email::MIME->create_html support Reply-to option?

I have been upgrading some Perl sendmail automated emails to take advantage of features with Email::MIME::CreateHTML and Email::Sender notably SMTP authentication. It works fine.
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP ();
use Email::MIME::CreateHTML;
my $smtpserver = 'myserver.com';
my $smtpport = ###;
my $smtpuser = 'noreply#mywebsite.com';
my $smtppassword = 'mypassword';
my $xport = Email::Sender::Transport::SMTP->new({
host => $smtpserver,
port => $smtpport,
ssl => 'ssl',
sasl_username => $smtpuser,
sasl_password => $smtppassword,
});
my $email = Email::MIME->create_html(
header => [
To => $email_to_recipient,
From => $email_from_person,
Subject => $email_subject_line,
],
body => $email_body_code,
);
sendmail($email, { transport => $transport });
However, I have not been able to find anywhere in the documents how to add a Reply-to option. Using sendmail it was as simple as adding another line:
print SENDMAIL "From: noreply\#myserver.com\n";
print SENDMAIL "To: recipient#theirserver.com";
print SENDMAIL "Reply-to: replyhere#myserver.com\n";
Tried to sneak in:
my $email = Email::MIME->create_html(
header => [
To => $email_to_recipient,
From => $email_from_person,
Reply-to => $email_reply_to_person,
Subject => $email_subject_line,
],
body => $email_body_code,
);
sendmail($email, { transport => $transport });
but the reply-to part was ignored. Any help would be appreciated.

VERP and perl postfix not working

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,
);

Connect failed :IO::Socket::INET: connect: timeout is showing up in Perl .

I have wriiten this script to send mail through gmail smtp to my gmail account . It is not working and giving the already mentioned error ?
use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
'smtp.gmail.com',
Hello => 'smtp.gmail.com',
Port => 587,
User => 'cetranger#gmail.com',
Password=> 'xxxxxx');
$mailer->mail('cetranger#gmail.com');
$mailer->to('cetranger#gmail.com');
$mailer->data;
$mailer->datasend("Sent from perl!");
$mailer->dataend;
$mailer->quit;
Try this:
use strict;
use warnings;
use Email::Simple;
use Email::Sender::Simple qw(sendmail);
use Email::Sender::Transport::SMTP::TLS;
my $transport = Email::Sender::Transport::SMTP::TLS->new(
host => 'smtp.gmail.com',
port => 587,
username => 'cetranger#gmail.com',
password => 'xxxxxx'
);
my $message = Email::Simple->create(
header => [
From => 'cetranger#gmail.com',
To => 'cetranger#gmail.com',
Subject => 'Sent from perl!',
],
body => 'Sent from perl!',
);
sendmail( $message, {transport => $transport} );
This script should work in fact (I tested with my own gmail account successfully).
I suspect you have some firewall in-between that prevent you from connecting to gmail.
Could you try telnet smtp.gmail.com 587 from your host. You should have something like that:
host$ telnet smtp.gmail.com 587
Trying 173.194.67.108...
Connected to gmail-smtp-msa.l.google.com.
Escape character is '^]'.
220 mx.google.com ESMTP da8sm6658151wib.6
If you do not have the last 3 lines, this means that you cannot connect directly to the gmail server. Then check as well your own firewall settings (if any).