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
Related
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 } );
you have an idea on how to solve this problem that I met with the function message_string () of Mail::IMAPClient library, here is my code:
#!/usr/bin/perl -w
use strict;
use warnings;
use Mail::IMAPClient;
use IO::Socket::SSL;
# Create the object connexion with socket SSL + LOG ON
my $imap = Mail::IMAPClient->new(
#Debug => 1,
User => 'xxxxx',
Password => 'yyyyy',
Uid => 1,
Peek => 1, # set \Seen flag
Socket => IO::Socket::SSL->new(
Proto => 'tcp',
PeerAddr => 'zzzzzzz',
PeerPort => 993,
)
);
die "$0: connect: $#" if defined $#;
my $nm=$imap->unseen_count("INBOX") ;
# Select INBOX dossier
$imap->select("INBOX");
my $msg = $imap->message_string('47') or die " $#\n";
the error obtained is the following:
message_string() expected 304627 bytes but received 304718 you may need the IgnoreSizeErrors option
The error message tells you exactly how to cope with this. Some IMAP servers calculate the message size incorrectly -- in particular, many (such as notably GMail) examine the local message size, then change the line terminators to CRLF when sending the message over IMAP, resulting in a slightly different actual size than what the server told the client to expect. By default, IMAPClient will throw an error when this happens, but you can tell it not to by saying IgnoreSizeErrors => 1 when you create an instance.
my $imap = Mail::IMAPClient->new(
#Debug => 1,
User => 'xxxxx',
Password => 'yyyyy',
Uid => 1,
Peek => 1, # set \Seen flag
Socket => IO::Socket::SSL->new(
Proto => 'tcp',
PeerAddr => 'zzzzzzz',
PeerPort => 993,
),
# See here
IgnoreSizeErrors => 1
);
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.
I'm trying to send emails from my gmail account, and get the error:
Error sending email: Connect failed :IO::Socket::INET: connect: timeout at /home/tas/perl5/lib/perl5/Email/Send/SMTP/TLS.pm line 45
I've tried several different email adresses (gmail and others) but the result is the same.
I use this code:
#!/usr/bin/perlml
use Email::Send;
print "Content-type: text/html\n\n";
my $mailer = Email::Send->new( {
mailer => 'SMTP::TLS',
mailer_args => [
Host => 'smtp.gmail.com',
Port => 587,
User => 'XXXX#gmail.com',
Password => 'XXXXXXXXX',
Hello => 'fayland.org',
]
} );
use Email::Simple::Creator; # or other Email::
my $email = Email::Simple->create(
header => [
From => 'XXXX#gmail.com',
To => 'XXXX#gmail.com',
Subject => 'test',
],
body => 'test',
);
eval { $mailer->send($email) };
die "Error sending email: $#" if $#;
What is wrong here? Any other ways to send emails using smtp?
Error sending email: Connect failed :IO::Socket::INET: connect: timeout at /home/tas/perl5/lib/perl5/Email/Send/SMTP/TLS.pm line 45
Looks like there is nothing wrong with your Perl code. It looks like this is a networking problem. Something in your network is preventing you from connecting to Gmail on port 587.
You probably need to discuss this with the system support people for your server.
I am trying to write a script which will send Gmail from a server using Perl. The code is as shown.
use warnings;
use strict;
use Email::Sender;
use Email::Send::Gmail;
use Email::Simple::Creator;
my $email = Email::Simple->create (
header => [
From => 'xxxx#gmail.com',
To => 'yyyyy#gmail.com',
Subject => 'Oh no! The bathwater is overflowing!',
],
body => 'The bath water is overflowing.',
);
my $sender = Email::Send->new ({
mailer => 'Gmail',
mailer_args => [
username => 'xxxxx',
password => 'yyyyy',
]
});
$sender->send ($email);
For which I get the error `Can't locate object method "create" via package "Email::Simple" at file.pl line 9.`
What is causing this error as I have installed Email::Simple Module and Gmail Modules.
You're missing use Email::Simple; as perldoc suggests.