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

Re: [MacPerl] Using MacPerl to send mail by SMTP (fwd)



I've found that using ANY perl libs for SMTP is a pain, so I wrote my own
script that deals with the sockets directly:

#!/usr/bin/perl
use Socket;
	my $serv = "mail.clarityconnect.com";
	my $addy = "Strider\@baka.com";
	print "\nEnter the address to send to> ";
	chop (my $to = <>);
	print "Enter the subject> ";
	chop (my $subject = <>);
	print "\nEnter the message, type s on a separate line when done.\n";
	while (<>){
		last if ($_ =~ /^s\n/i);
		chop ($_ = $_);
		my $message .= $_;
		my $message .= "\015\012";
	}


	$/ = "\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 "\nMailing Complete.\n";

pretty soon I'm going to make this into a no-frills perl module.

BTW- anyone have any idea why it runs slow as sin on a linux box?

-Strider



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