http://www.perlmonks.org?node_id=1027874

ungalnanban has asked for the wisdom of the Perl Monks concerning the following question:

I'm using Mail::Sender , I'm getting the error message as
connection not established.
I'm using OpenMultipart to fill up the hash. when this error will come? how to solve this? If I send 10 mails, only 2 mails successfully send , remaining mails got this error.
$Msg = new Mail::Sender ( { smtp => SMTP_IP, debug_level => 4, port => '2255', debug => '/tmp/mail_sync.log' } ); $Msg->OpenMultipart({ from => xxxx@gmail.com, to => xxxx@gmail.com, subject => testing, debug => '/tmp/log.log', multipart => 'related', }) ->Part({ctype => 'multipart/alternative'}) ->Part({ctype => 'text/html', disposition => 'NONE', msg => " <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN> <html> <head> </head> <body bgcolor=#ffffff text=#000000> xxxxx ( Some HTML Content ) </body> </html>" }) ->EndPart("multipart/alternative"); $Msg->Attach({ description => 'fax1 jpg', ctype => 'image/jpeg', encoding => 'base64', disposition => "attachment; filename=1111;", file => 'filename', }); $Msg->Close(); }
debug log file:
>> 220 nsmtpin.xxxxb.co.in ESMTP Service (Lotus Domino Release 8.5.2) +ready at Wed, 10 Apr 2013 00:42:28 +0530 << EHLO localhost >> 250-nsmtpin.xxxxb.co.in Hello localhost ([10.2.252.251]), pleased t +o meet you >> 250-HELP >> 250-SIZE 5324800 >> 250 PIPELINING << MAIL FROM:<xxxxx@xxxxB.com> >> 250 xxxxxx@xxxxB.com... Sender OK << RCPT TO:<xxx@xxxxB.com> >> 250 xxx@xxxxB.com... Recipient OK << DATA >> 354 Enter message, end with "." on a line by itself << To: xxxx@xxxxB.com << From: xxx.xxx@xxxxB.com << Subject: Testing << Date: Wed, 10 Apr 2013 00:35:42 +0530 << X-Mailer: Perl script "Email_Resender" << using Mail::Sender 0.8.16 by Jenda Krynicky, Czechlands << running on localhost (127.0.0.1) << under account "root" << Message-ID: <20130409_190542_084621.Mitesh.Shah@xxxxB.com> << MIME-Version: 1.0 << Content-type: multipart/related; << boundary="Message-Boundary-by-Mail-Sender-1365534342" << << This message is in MIME format. Since your mail reader does not und +erstand << this format, some or all of this message may not be legible. << << --Message-Boundary-by-Mail-Sender-1365534342 << Content-Type: multipart/alternative; boundary="Part-Message-Boundar +y-by-Mail-Sender-1365534342_2" << << << --Part-Message-Boundary-by-Mail-Sender-1365534342_2 << Content-type: text/html << Content-transfer-encoding: 7BIT << << << << <!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.0 +1 Transitional//EN> << <html> << << </html> << --Part-Message-Boundary-by-Mail-Sender-1365534342_2-- << << --Message-Boundary-by-Mail-Sender-1365534342 << Content-type: image/jpeg; name="20130408_112508_2792230080_1_4.jpg" << Content-description: fax1 jpg << Content-transfer-encoding: base64 << Content-disposition: attachment; filename=08042013/20130408_112508_ +2792230080_1_4.jpg; << << /9j/4AAQSkZJRgABAQEAzABiAAD//gAbPFVOU1BFQ0lGSUVEPgoyNzkyMjMwMDgwCv/ +bAEMABQME << BAQDBQQEBAUFBQYHDAgHBwcHDwsLCQwRDxISEQ8RERMWHBcTFBoVEREYIRgaHR0fHx8 +TFyIkIh4k << HB4fHv/AAAsIA+gDIAEBEQD/xAAdAAEAAgMBAQEBAAAAAAAAAAAABQYDBAcCAQgJ/8Q +AdhAAAQME << fWbj6/DL+rsQgf8Ad/VX4L6Wzr/beo2PTcWQpy9N3Fn0JtP/AGRwrACD9St8T9RNf1y +Ry4DkAFa7 << gHeqj8nvVvxzHbhfrq+GINvjrkPrPsQkbOvefYB7yK578HfqZL6lYhMeukL4qv0N7b8 +UoIKWHh4s << jkjkT7dBQH2VhR8HzCUFRRdcxSVq5K1kcobPbufW8+wr1/g/4Z/S+Z/rLK/aqUt3RXB +okRLDjF2m << qDnPxpd3kuOEfilXMer9VbbXSHAkNpQbQ+spAHJdxklR+snxO5r180eA/wBCufeEn95 +T5o8B/oVz << 7wk/vKfNHgP9CufeEn95T5o8B/oVz7wk/vKfNJgP9CufeEn95Uc50G6QuuKcdwKzOOL +JUpa0KUpR << PmSSrZP1mvnzBdHfzfWP/ZK/aoOgfR4EEdPrHsHf8ir++p+P0z6exw8GsKx5Pjnbn+5 +zR3217U9u << 3u1Wdvp9giEJQnDcd4pAA/3LYPYf/Fr78gMG/I3Hfutj9inyAwb8jcd+62P2KfIDBvy +Nx37rY/Yp << 8gMG/I3Hfutj9ivbWC4U0dtYjYEE+1NsYH/5Ne/kViHLl8lrHsjW/i5ny/1ayxcTxiL +JbkxsdtDD << zSgttxuC0lSFDyIITsH6xUzxH1/aacR9f2mvoGvf9tKUpSlKUr//2Q== << quit

Replies are listed 'Best First'.
Re: connection not established. error in Mail::Sender
by Loops (Curate) on Apr 10, 2013 at 02:46 UTC

    You need to test return values to see what is happening at each stage of your program. For instance, what return value is $Msg->Close() generating? If it's 0, it means that something failed in the creation of the message and no attempt to connect to the server was even made.

    That info is here: Close and send your message

      I'm sending mail one by one. I have checked the debug log file, It shows "This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible." at the end of file, its simply quit. Is there any link between this MIME error message and connection not established. my $Msg->Close() returns 0,

        The "This message is in MIME format. ..." is just a message for the (I believe very rare) people that use a mail client that do not understand MIME (the standard that defines all those headers and stuff allowing you to send multipart messages, attachments etc.) Ignore it.

        I don't understand what where gives you that error. There's something you haven't shown.

        Jenda
        Enoch was right!
        Enjoy the last years of Rome.

Re: connection not established. error in Mail::Sender
by BrianDSy (Initiate) on Aug 28, 2013 at 21:15 UTC

    I hope it's OK to revive this thread. I'm getting the same error message, after switching hosts all my scripts broke. Changing hosts also involved changing from dedicated IP to shared. Which may be relevant because the host service puts a perl path in the environment which points to a folder with a file called ReadOnly.pm, which at a glance seems to restrict changing values in the stack for objects like scalars and arrays in the installed CPAN modules. I'm testing Mail::Sender with a commandline script. I know the smtp settings work because I'm able to send a simple message using Net::SMTP::SSL but the same settings always time out When I run with perl debug flag and check the value of my hash it all looks ok.


    Here's the contents of the $self hash from perl5/lib/perl5/Mail/Sender.pm: line 1022):
    1022: return $self; DB<15> x $self + 0 Mail::Sender=HASH(0x2b06c40) 'authid' => 'webmaster@mydomain.org' 'authpwd' => 'thepassword' 'boundary' => 'Message-Boundary-by-Mail-Sender-1377721215' 'client' => 'hostnnn.hostmonster.com' 'debug' => 1 'from' => 'webmaster@mydomain.org' 'fromaddr' => 'webmaster@mydomain.org' 'keepconnection' => 1 'multipart' => 'mixed' 'on_errors' => 'code' 'port' => 465 'proto' => 6 'reply' => 'info@mydomain.org' 'replyaddr' => 'info@mydomain.org' 'smtp' => 'mail.mydomain.org' 'smtpaddr' => 'J?&#1009;' 'tls_allowed' => 1

    And here's the $self hash from right before the call to $self->Connect(); on line 1322, I'm a little unsure about smtpaddr value. Using localhost gives me something that looks like a local ip address that's been packed. When it calls $self->Connect(); the script times out.

    1322: my $s = $self->{'socket'} || $self->Connect(); DB<3> x $self + 0 Mail::Sender=HASH(0x237e5f0) '_had_newline' => 1 'authid' => 'webmaster@mydomain.org' 'authpwd' => 'therightpassword' 'boundary' => 'Message-Boundary-by-Mail-Sender-1377722649' 'client' => 'abcdefg.hostserver.com' 'debug' => 1 'from' => 'webmaster@mydomain.org' 'fromaddr' => 'webmaster@mydomain.org' 'keepconnection' => 1 'multipart' => 0 'on_errors' => 'code' 'port' => 465 'proto' => 6 'reply' => 'info@mydomain.org' 'replyaddr' => 'info@mydomain.org' 'smtp' => 'mail.mydomain.org' 'smtpaddr' => 'J?&#1009;' 'subject' => 'smtp-ssl-auth test with Mail Sender module' 'tls_allowed' => 1 'to' => 'devmail@mydomain.org' 'to_list' => ARRAY(0x1eecbe0) 0 'devmail@mydomain.org'

    And here's the code I'm using;
    #!/usr/bin/perl use strict; use warnings; use Mail::Sender; ## use Carp (); ## local $SIG{__WARN__} = \&Carp::cluck; BEGIN { my $b__dir = (-d '/home2/avantclo/perl'?'/home2/avantclo/perl':( getpw +uid($>) )[7].'/perl'); unshift @INC,$b__dir.'5/lib/perl5',$b__dir.'5/lib/perl5/x86_64-linux-t +hread-multi',map { $b__dir . $_ } @INC;} my $user = 'webmaster@mydomain.org'; my $pass = 'TheRightPassword'; my $mlserver='mail.mydomain.org'; my $replyaddey='info@mydomain.org'; my $smtpaddey= 'localhost'; my $to='devmail@mydomain.org'; my $from_name='Webmaster'; my $from_email='webmaster@mydomain.org'; my $subject='smtp-ssl-auth test with Mail Sender module'; my $html="<html><body>Test HTML content</body></html>"; my $debugon = 1; my $debugoff = 0; my $portnum = 465; my $errorset = "code"; my $keepconn = 1; my $tlsreq = 1; $Mail::Sender::NO_X_MAILER = 1; open my $DEBUG, ">> ../../test/testsender1debugfile.txt" or die "Can't open the debug file: $!\n"; my $smtps = Mail::Sender->new({ smtp=>($mlserver), port=>($portnum), authid=>($user), authpwd=>($pass), from=>($from_email), reply=>($replyaddey), debug=>($debugon), on_errors => ($errorset), keepconnection=>($keepconn), TLS_allowed=>($tlsreq)}); $smtps->Open({ to=>($to), from=>($from_email), subject=>($subject)}); defined (ref $smtps) or die "Failed to open the message: $smtps->{ +'error_msg'}\n"; $smtps->SendLineEnc($html); $smtps->SendLineEnc("This will be the body of the message.\n") +; $smtps->SendLineEnc("\n--\nVery Official Looking .sig here\n") +; if ($Mail::Sender::Error eq '') { print "Test message has been sent\n"; } else { die "Failed to send the message: $smtps->{'error_msg'}\n"; } $smtps->Close();