Solved

Unable to send an email from perl script.

Posted on 2009-06-27
9
1,090 Views
Last Modified: 2013-12-18
I am trying to send an email from a perl script using MIME::Lite.  I see this error:
"5.7.0 Must issue a STARTTLS command first",

The email doesn't go out.  I am newbie in this area, please give me step-by-step instructions to resolve this.

Note that I have disabled firewall, but saw no difference.  Also, I tried ports 465 and 587.

This is the perl script I am using:
#!/usr/bin/perl -w
 
# use MIME::Lite package
use MIME::Lite;
 
# set up email
$to = "yyyy\@gmail.com";
$from = "yyyy\@gmail.com";
$subject = "Email Sent via Perl";
$message = "This email was sent using Perl.";
$file = "abc.html";
 
# send email
email($to, $from, $subject, $message, $file);
 
# email function
sub email
{
 # get incoming parameters
 local ($to, $from, $subject, $message, $file) = @_;
 
 # create a new message
 $msg = MIME::Lite->new(
  From => $from,
  To => $to,
  Subject => $subject,
  Data => $message
 );
 
 # add the attachment
 $msg->attach(
  Type => "text/plain",
  Path => $file,
  Filename => $file,
  Disposition => "attachment"
 );
 
 # send the email
 MIME::Lite->send('smtp', 'smtp.gmail.com', Timeout => 60);
 $msg->send();
}

Open in new window

0
Comment
Question by:Folsomite
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
9 Comments
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 24730228
Did you want to specify a mail host of 'smtp.gmail.com' ? The host would normally be the name of the host mail server provided by your ISP, or work organization, one which you have an account setup. It may also need a username and password specified.
0
 

Author Comment

by:Folsomite
ID: 24730264
All the examples I have seen online show host is smtp.gmail.com (when using gmail account to send the email).  The gmail help page also says the same thing: http://mail.google.com/support/bin/answer.py?hl=en&answer=13287

What is the syntax for specifying the username and password?
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 24730931
The problem seems to be the need to use TLS or secure sockets, which MIME::Lite will not support. You could try this module http://search.cpan.org/~mincus/Mail-Webmail-Gmail-1.09/lib/Mail/Webmail/Gmail.pm and use specify your password and username
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:Folsomite
ID: 24731530
SSL is not installed on my machine; however, installing SSL from cpan website seems almost impossible task, because SSL needs SSLeay, TLS and other perl modules.  This thread gives the various issues with getting the SSL installed: http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/Q_22873843.html?sfQueryTermInfo=1+perl+ssl

As for the module teraplane suggested, it in turns needs SSLeay to work---which I couldn't successfully install, look at the above thread for details on the issues.
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 24734862
Is gmail your only option? It would be much easier to use a POP mail account if you hace access to one.
0
 

Author Comment

by:Folsomite
ID: 24736528
I have att.net email account which ,I think, is a POP mail account (http://www.wurd.com/settings.php#Accessing). I updated my script to use att email and server, but I am seeing other errors.  

If you have an example of a working script with POP mail account, could you forward it (of course, without password and user ID)?
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 500 total points
ID: 24744441
The example you have looks fine. Just change the send command to something like this

MIME::Lite->send('smtp','some.host',
       AuthUser=>$user, AuthPass=>$pass);
$msg->send();
0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 24778491
Any luck with my last suggestion?
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This process describes the steps required to Import and Export data from and to .pst files using Exchange 2010. We can use these steps to export data from a user to a .pst file, import data back to the same or a different user, or even import data t…
When you’re making plans to join the modern business race, you should analyze various details that may affect your results. Nowadays, millions of businesses are trying to grow into established and appreciated professional enterprises.
In this video we show how to create an email address policy in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.:  First we need to log into the Exchange Admin Center. Navigate to the Mail Flow…
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question