Rey Norbert Besmonte
Rey Norbert Besmonte

Reputation: 791

Perl Email function Mime::Lite

Im fairly new to Perl programming. I need help on the basic SMTP using MIME::Lite, I have already downloaded the library and put it on the folder. Here is my code

#!/usr/bin/perl

use MIME::Lite;
use Net::SMTP;

$to = '[email protected]';
$cc = '[email protected]';
$from = '[email protected]';
$pass = "my password here";
$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
                 );

# MIME::Lite->send('smtp', "smtp.gmail.com");
MIME::Lite->send('smtp', "smtp.gmail.com", Timeout=>60,Auth=>'LOGIN',AuthUser=>$from,AuthPass=>$pass,Port => 465, Debug => 1);
$msg->send;
print "Email Sent Successfully\n";

I'm getting an error of:

MIME::LITE::SMTP>>> MIME::LITE::SMTP
MIME::LITE::SMTP>>> NET::SMTP(3.10)
MIME::LITE::SMTP>>> NET::CMD(3.10)
MIME::LITE::SMTP>>> EXPORTER(5.72)
MIME::LITE::SMTP>>> IO::SOCKET::IP(0.39)
MIME::LITE::SMTP>>> IO::SOCKET(1.38)
MIME::LITE::SMTP>>> IO::HANDLE(1.36)
MIME::LITE::SMTP>>> NET::CMD::GETLINE(): UNEXPECTED EOF ON COMMAND CHANNEL: AT C:/STRAWBERRY/PERL/LIBE/MIME/LITE.PM LINE 2622 AT MAIN.PL LINE 23
SMTP FAILED TO CONNECT TO MAIL SERVER: BAD FILE DESCRIPTOR AT LINE 23

Am I missing something here? I saw the tutorial and it is working for them.

Upvotes: 0

Views: 3163

Answers (1)

Rey Norbert Besmonte
Rey Norbert Besmonte

Reputation: 791

Thanks for everyone's advice. So Since Mime::lite not that good I changed my approach to Net::SMTP. Here is my code below for future reference.

Also note that I was not able to make it work for google but our own smtp server work fine for the code.

#!perl
use warnings;
use strict;
use Net::SMTP;

my $smtpserver = 'mail server';
my $smtpport = 'port' ;
my $smtpuser   = '[email protected]';
my $smtppassword = 'my password';


my $smtp = Net::SMTP->new($smtpserver, Port=>$smtpport, Timeout => 60, Debug => 1);
die "Could not connect to server!\n" unless $smtp; 

$smtp->auth($smtpuser, $smtppassword);
$smtp->mail('[email protected]');
$smtp->to('[email protected]');

$smtp->data();
$smtp->datasend("To: receiver name <receiver\@sample.com>\n");
$smtp->datasend("From: sender name <sender\@sample.com>\n");
$smtp->datasend("subject: THIS IS A SUBJECT\n");
$smtp->datasend("\n");
$smtp->datasend("A simple test message\n");

$smtp->quit;

Upvotes: 2

Related Questions