LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 03-25-2003, 02:31 PM   #1
meluser
Member
 
Registered: Mar 2003
Posts: 65

Rep: Reputation: 15
script to send email message


Hi,

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 email.pl
Content-type: text/plain

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


Regards,

Mel

---------------------email.pl

#!/usr/local/bin/perl

use Net::SMTP;

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

my $DEBUG = 1;

if($DEBUG)
{
$| = 1;
open(STDERR, ">&STDOUT");
}

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

# 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\@hotmail.com";

# Recipient's "real" email address
my $MailTo = "cctv_alert\@hotmail.com";

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

# Start the mail
$smtp->data();

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

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

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

# Send the termination string
$smtp->dataend();

# Close the connection
$smtp->quit();
 
Old 03-25-2003, 02:59 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

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

Rep: Reputation: 145Reputation: 145
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
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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

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