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

Hi, I am new to perl. Tried to run a script and it's throwing some error:
SMTP Failed to connect to mail server : at test1.pl line 17
below is the code I tried to run.
#!/usr/bin/perl use MIME::Lite; $to = 'bhaskarpate24X7@gmail.com'; $cc = ''; $from = 'bhaskarpatel24X7@gmail.com'; $subject = 'Test Email'; $message = 'This is test email sent by Perl Script'; $msg = MIME::Lite->new( From => $from, To => $to, Cc => $cc, Subject => $subject, Data => $message ); #my $mailer = 'Windows 7 Ultimate'; #$msg->send_by_smtp($mailer); # do some error checking $msg->send; print "Email Sent Successfully\n";
Please help me ASAP. Thanks

Replies are listed 'Best First'.
Re: PERL MIME:LITE
by Corion (Patriarch) on Jan 18, 2014 at 16:44 UTC

    What operating system are you using?

    Can the machine you are running the script on send mail otherwise? Maybe there are network problems or a firewall setup that prevents the machine from sending mail.

      Hi Corion,

      I am using Windows 7.

      Through my mail_id am able to send mail. By using this script only getting this error. Thanks in advance..

        What do you mean by "mail id"?

        Is your machine capable of talking to an SMTP server and sending mail there?

        Consider using the documented method of the ->send method:

        $msg->send('smtp','some.host', Debug=>1 );

        or alternatively, pass Debug => 1 in the constructor.

        That way, maybe you see some more specific output of what goes wrong.

        The most likely cause is that outgoing network traffic to port 25 is blocked. You will then have to consult with your network administrator on how to best proceed.

Re: PERL MIME:LITE
by karlgoethebier (Abbot) on Jan 18, 2014 at 14:33 UTC

    BTW, you noticed this?

    "MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else."

    See MIME::Lite.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Hi Karl,

      Below is the code I tried for single user that's fine but attachment and multiple user when I tried it throws error.Please suggest me what should I try now. Thanks in advance
      #!/usr/bin/perl use strict; use warnings; use LWP::Simple; use Email::Send; use Email::Send::Gmail; use Email::MIME::Creator; use IO::All; my $url = "https://www.google.co.in/?gws_rd=cr&ei=VJzjUrT3LMaPrgeQ +5oHQDg/csv"; my $file = "C:\Users\Administrator\Desktop\a.csv"; my $status = mirror($url,$file); die "Cannot retrieve $url" unless is_success($status); my $url1 = "https://www.google.co.in/?gws_rd=cr&ei=VJzjUrT3LMaPrge +Q5oHQDg/csv"; my $file1 = "C:\Users\Administrator\Desktop\a.csv"; my $status1 = mirror($url1,$file1); die "Cannot retrieve $url" unless is_success($status1); my $email = Email::MIME->create( header => [ From => 'abc@gmail.com', To => 'abc@gmail.com', Subject => 'Test Mail', Message => ' Hi , How are you? Test mail please ignore. Thanks, ', CC => 'abc@gmail.com' ], ); attributes => [ { filename =>"a.csv", content_type =>"application/csv", disposition =>"attachment", Name =>"C:\Users\Administrator\Desktop\a.csv", }, body => io( "C:\Users\Administrator\Desktop\a.csv" )->all, { filename =>"a.csv", content_type =>"application/csv", disposition =>"attachment", Name =>"C:\Users\Administrator\Desktop\a.csv", }, body => io( "C:\Users\Administrator\Desktop\a.csv" )->all, ], ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args => [ username => 'abcgmail.com', password => 'abcd0000', ] } ); eval { $sender->send($email) }; die "Error sending email: $@" if $@;
        "Could you please explain how..."

        I'll try. I assume you use Active State Perl, right?

        If so, please see this instructions.

        Else give some feedback/ask again.

        Best regards, Karl

        «The Crux of the Biscuit is the Apostrophe»

Re: PERL MIME:LITE
by Kenosis (Priest) on Jan 18, 2014 at 06:32 UTC

    Welcome, Bhaskar Patel, to PerlMonks!

    To help us assist you, please enclose your script within code tags, to help with its readability.