Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-29-2007, 03:03 AM   #1
Registered: Sep 2005
Distribution: Ubuntu
Posts: 250

Rep: Reputation: 30
Problems with perl sending email with Gmail SMTP

I am trying to send a message with a perl script using the Net::SMTP::TLS module. I can send it using some SMTP servers, but I cannot get gmail's SMTP to work, or Yahoo's.

I disabled all firewalls. If I use this code:
1 #!/usr/bin/perl -w
2 use warnings;
3 use strict;
5  use Net::SMTP::TLS;
6  my $EMAIL_SMTP='';
7  my $EMAIL_HELLO='';
8  my $EMAIL_PORT=587;
9  my $EMAIL_PASSWORD='password';
11  my $mailer = new Net::SMTP::TLS
12    (
13      $EMAIL_SMTP,
14      Hello   =>      $EMAIL_HELLO,
15      Port    =>      $EMAIL_PORT,
16      User    =>      $EMAIL_SENDER,
17      Password=>      $EMAIL_PASSWORD,
18    );
19  $mailer->mail('');
20  $mailer->to('');
21  $mailer->data;
22  $mailer->datasend("Sent thru TLS!");
23  $mailer->dataend;
24  $mailer->quit;
The script reports:
Use of uninitialized value in pattern match (m//) at /usr/local/share/perl/5.8.8/Net/SMTP/ line 140, <GEN0> line 7.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.8.8/Net/SMTP/ line 396, <GEN0> line 7.
Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Net/SMTP/ line 397, <GEN0> line 7.
Use of uninitialized value in concatenation (.) or string at /usr/local/share/perl/5.8.8/Net/SMTP/ line 397, <GEN0> line 7.
An error occurred disconnecting from the mail server:
at line 11
Now, something DOES get sent to my gmail account. But the message shows up in the spam folder, because it has no subject and no message body. All it says in gmail is this:

from "" <>
date Jul 29, 2007 12:55 AM
But there is nothing else. No message body or subject. I would love some help with this. I have confirmed that the module does work, since I can send email through my college account, but I need to be able to use some SMTP server (gmail or yahoo or whatever).
Old 03-19-2008, 03:26 AM   #2
LQ Newbie
Registered: Mar 2008
Posts: 1

Rep: Reputation: 0
Gmail uses SSL and not TLS

It's too late to answer the question, never-the-less, for anyone else: gmail uses SSL and not TLS. Therefore you need to use Net::SMTP::SSL.
Old 10-01-2008, 10:43 AM   #3
LQ Newbie
Registered: Oct 2008
Location: Stockholm, Sweden
Distribution: Ubuntu
Posts: 1

Rep: Reputation: 0
Gmail appears to quit without sending a 221 response

Gmail does support TLS on port 587 as well as SSL.

I am getting the same problem. When Email::Send::SMTP::TLS sends the SMTP QUIT command, Gmail appears to just disconnect rather than sending back a 221 response expected by Email::Send::SMTP::TLS.

I made these two changes below to get it to work.

I don't get the empty message you have, but I note your HELO entry is set to Gmail's address rather than your own hostname.


sub quit:

if(not $num == 221){
if($num && not $num == 221){

sub _response


unless (defined $line) {return ('','','')}
Old 09-12-2009, 07:17 PM   #4
LQ Newbie
Registered: Sep 2009
Posts: 1

Rep: Reputation: 0

Try adding a carriage return as the first line of your message (the body). Worked for me using Net::SMTP::TLS with ActivePERL on Win XP. Good luck.

Like this...

$mailer->datasend("Sent from perl!");


email, gmail, mail, perl, script, smtp, ssl, tls

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is PostFix sending mail using the email address of the smtp account? taigon Linux - Server 34 02-09-2007 01:09 AM
Problems sending emails received on Gmail bogdan.dusa Linux - Software 6 06-13-2006 05:53 PM
Sending Email to an SMTP address from sendmail guilmetrp Linux - Newbie 6 03-01-2004 08:51 PM
Sending email to a smtp address through sendmail guilmetrp Linux - General 0 02-27-2004 08:02 PM
sending an email to a email address after a perl operation meluser Programming 9 04-07-2003 01:26 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:53 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration