[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Using MacPerl to send mail by SMTP



I've had major problems getting MacPerl to send mail by smtp but 
Strider's
suggestion (posted yesterday) finally did the trick. It doesn't require 
any lib modules apart from Socket.pm. (I've had numerous problems in 
getting smtp scripts requiring lib modules to work, mostly due to my 
inexperience, no doubt).
Below is Strider's script, modified to run as a cgi.

#########################################################
#!perl

use Socket;

#########################################################
my $serv = "smtp.yourdomain.com"; #your mail server
my $addy = 'you@yourdomain.com'; #the sender
my $subject = 'A Message';       #the title of the message
my $to =  'recip@somedomain.com'; # the recipient
my $message = 'Hi there, just testing'; # the body of the message
##########################################################
   print "HTTP/1.0 200 OK\n";			#print the http header
   print "Content-type: text/html\n\n";
   print "<html><body>\n";
##########################################################
# the business end
	$/ = "\015\012";

	socket(Seraph, PF_INET, SOCK_STREAM, 6);

		my $sin = sockaddr_in("25",inet_aton("$serv"));

		my $conn = connect(Seraph,$sin);

		select((select(Seraph),$| = 1)[0]);

		die "Connection couldn't be made. $!" if ($conn != 1);

		my $msg = <Seraph>;

	#	print "$msg";

		if ($msg !~ /^220/) {die "Host not responding correctly";}

		print Seraph "EHLO\015\012";

		my $msg = <Seraph>;

#		print "$msg";

		if ($msg !~ /^250/) {die "Host not responding correctly";}


		my $msg = <Seraph>;

		my $msg = <Seraph>;

		my $msg = <Seraph>;


		print Seraph "MAIL FROM: <$addy>\015\012";

	 my $msg = <Seraph>;

		#print STDOUT "$msg";

		if ($msg !~ /^250/) {die "Host not responding to MAIL FROM: command 
correctly";}


		print Seraph "RCPT TO: <$to>\015\012";

		my $msg = <Seraph>;

		#print STDOUT "$msg";

		if ($msg !~ /^250/) {die "Host not responding to RCPT TO: command 
correctly";}


		print Seraph "DATA\015\012";

		my $msg = <Seraph>;

		#print STDOUT "$msg";

		if ($msg !~ /^354/) {die "Host not responding to DATA command
correctly";}


		print Seraph "Subject: $subject\015\012\015\012";

		print Seraph "$message\015\012";

	 print Seraph ".\015\012";

		my $msg = <Seraph>;

		# print STDOUT "$msg";

		if ($msg !~ /^250/) {die "Host not accepting DATA correctly";}

	#	print STDOUT "Mail sent.\n";

	 print Seraph "QUIT\015\012";

		my $msg = <Seraph>;

	#	print STDOUT "$msg";

		if ($msg !~ /^221/) {die "Host didn't quit properly";}

	close(Seraph);
print "Mailing Complete.\n";




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch