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
);
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 } );
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
Objective is to get the "dn" attribute of all the computers in my Active Directory server.
When the code executes I get: "000004DC: LdapErr: DSID-0C090752, comment: In order to perform this operation a successful bind must be completed on the connection."
Here is my code:
#!/usr/bin/perl
use strict;
use Net::LDAP;
use Data::Dumper;
my $ldap = Net::LDAP->new( 'my.domain.com' ) or die $#;
my $user = 'CN=username,OU=orgname,DC=my,DC=domain,DC=com';
my $pass = 'my_password';
$ldap->bind($user, password => $pass);
#$ldap->bind;
my $mesg = $ldap->search(
base => "DC=my,DC=domain,DC=com",
filter => "ObjectClass=Computers",
attrs => "dn"
);
I've tested the user / password to log into the domain directly with success.
Additional information if I add this to the end of the script: print Dumper($mesg);
$VAR1 = bless( {
'parent' => bless( {
'net_ldap_version' => 3,
'net_ldap_scheme' => 'ldap',
'net_ldap_debug' => 0,
'net_ldap_socket' => bless( \*Symbol::GEN0, 'IO::Socket::INET' ),
'net_ldap_host' => 'my.domain.com',
'net_ldap_uri' => 'my.domain.com',
'net_ldap_resp' => {},
'net_ldap_mesg' => {},
'net_ldap_async' => 0,
'net_ldap_port' => 389,
'net_ldap_refcnt' => 1
}, 'Net::LDAP' ),
'errorMessage' => '000004DC: LdapErr: DSID-0C090752, comment: In order to perform this operation a successful bind must be completed on the connection., data 0, v2580',
'ctrl_hash' => undef,
'resultCode' => 1,
'callback' => undef,
'mesgid' => 2,
'matchedDN' => '',
'controls' => undef,
'raw' => undef
}, 'Net::LDAP::Search' );
Any suggestions on how to get this script working is what I'm looking for.
Thanks!
With regard to the error message you posted I would say the bind attempt failed.
It might help you to improve bind result:
$mesg = $_ldap->bind("***", password => "***");
$mesg->is_error && die join ';' $mesg->code, $mesg->error
See Net::LDAP:
The return value from these methods is an object derived from the
Net::LDAP::Message class. The methods of this class allow you to
examine the status of the request.
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 new in openLDAP and perl. I want to export /import LDAP data with/without schema from LDAP database. Is this possible to do that using perl script? If yes ,please give me a sample code.
I would like to create a new schema using openLDAP and perl without dns.How to do that?
This is too many questions in one item. Please ask one question at a time.
How to read Ldap from wtih Perl:
use strict;
use warnings;
use Data::Dumper;
### for ldap
use Convert::ASN1;
use Net::LDAP;
use Net::LDAP::Util qw(ldap_error_name canonical_dn ldap_explode_dn ldap_error_text);
use Net::LDAP::LDIF;
my %parms (
host => 'localhost',
port => 389,
binddn => 'your dn',
passwd => 'password',
base => "",
filter => "(objectclass=*)",
scope => "base",
attrs => ['*'],
);
my $ldif = Net::LDAP::LDIF->new( "out.ldif", "w", onerror => 'die', wrap => 0 );
my $ldap= Net::LDAP->new($parms{'host'}, port => $parms{'port'});
my $bind_result = $ldap->bind($parms{'binddn'},'password' => $parms{'passwd'},'version' => '3');
if($bind_result->is_error()) {
die ('Unable to bind to ' . $parms{'host'} . ': '.$bind_result->error());
}
my #search_args = (
'base' => $parms{"base"},
'scope' => $parms{'scope'},
'filter' => $parms{'filter'},
'attrs' => $parms{'attrs'},
'deref' => 'always',
);
my $msg = $ldap->search(#search_args);
if ($msg->is_error()) {
die "ERROR: ".Dumper(\#search_args).", ".$msg->error."\n";
}
while (my $entry = $msg->pop_entry()){
my $cn = $entry->get_value("cn");
print "cn: $cn\n";
}