Share your knowledge at the LQ Wiki.
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 03-25-2003, 03:31 PM   #1
Registered: Mar 2003
Posts: 65

Rep: Reputation: 15
script to send email message


I have been researching on this. i got a script when i try to run get an error connecting to server. This script i am just trying to get to work, but the main reason for this is to be able to insert it into another Perl script where i would like email to be sent automatically when the other part of the script does something!

[root@cctv cgi-bin]# perl
Content-type: text/plain

Couldn't connect to server at line 22.
[root@cctv cgi-bin]#




use Net::SMTP;

print "Content-type: text/plain", "\n\n";

my $DEBUG = 1;

$| = 1;
open(STDERR, ">&STDOUT");

# Set this variable to your smtp server name
my $ServerName = "smtp.";

# Create a new SMTP object
$smtp = Net::SMTP->new($ServerName, Debug => 1);

# If you can't connect, don't proceed with the rest of the script
die "Couldn't connect to server" unless $smtp;

# Initiate the mail transaction
# Your "real" email address
my $MailFrom = "cctv_server\";

# Recipient's "real" email address
my $MailTo = "cctv_alert\";

$smtp->mail( $MailFrom );
$smtp->to( $MailTo );

# Start the mail

# Send the header
# This address will appear in the message
$smtp->datasend("To: cctv_alert\\n");

# So will this one
$smtp->datasend("From: cctv_server\\n");
$smtp->datasend("Subject: Test Message\n");

# Send the body.
$smtp->datasend("Hello World!\n\n");

# Send the termination string

# Close the connection
Old 03-25-2003, 03:59 PM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 65
Personally I would use sendmail but I think the problem is that the line
my $ServerName = "smtp.";
should be
my $ServerName = "";
Old 03-26-2003, 01:35 AM   #3
Senior Member
Registered: Jan 2002
Location: germany
Distribution: ubuntu
Posts: 1,507

Rep: Reputation: 128Reputation: 128
add this and u will probably get a more detailed error message.

# If you can't connect, don't proceed with the rest of the script
die "Couldn't connect to server: $!" unless $smtp;

does the server require authentication?
cheers, jens


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
Script to send email... bfloeagle Linux - General 5 10-13-2009 11:20 AM
Send simple email message in C zaichik Programming 5 09-09-2005 11:27 AM
write a shell script to send email yenonn Programming 4 02-11-2005 11:06 PM
Write a script to send an email from bash kpelczar Linux - Software 5 02-09-2005 05:19 PM
Allowing an IP to send email using my email server... culprit Linux - Networking 7 09-09-2003 01:24 PM

All times are GMT -5. The time now is 04:25 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration