
darian
Deleted
Feb 16, 2000, 9:41 PM
Post #12 of 12
(1026 views)
|
|
Re: Specifying Subject: and To: fields with Net::SMTP
[In reply to]
|
Can't Post
|
|
kencl, Sendmail is a program an ISP can install to access the SMTP protocal. As you can see by perlkid's example, there is much less code involved then the example I have below. This example here uses sockets to communicate to the server to send mail via SMTP. SMTP Code: #!/usr/local/bin/perl #################################################################### # This smtp socket script was created by Johnny Hughes 4/25/98 # # # # http://ntperling.hypermart.net # # # # the below variables can come from a form...or be predefined... # # or any combination thereof, as long as they are all defined # # before the needed in the call below. This script is designed to # # be place inside another script, and is not fully fuctional by # # itself # #################################################################### #$emailfrom = 'abc@123.net'; #$recipient = 'def@123.net'; #$subject = 'This is a test mail'; #$message = 'This is a test message...did I get it'; $smtp_server = "mail.yourserver.com"; &email; sub email { ($x,$x,$x,$x, $here) = gethostbyname($null); ($x,$x,$x,$x, $there) = gethostbyname($smtp_server); $thisserver = pack('S n a4 x8',2,0,$here); $remoteserver = pack('S n a4 x8',2,25,$there); #NOTE, if Solaris, uncomment the line below and delete the one below it...leave alone for NT #(!(socket(S,2,2,6))) && (&error("Connect error!")); (!(socket(S,2,1,6))) && (&error("Connect error! socket")); (!(bind(S,$thisserver))) && (&error("Connect error! bind")); (!(connect(S,$remoteserver))) && (&error("!! connection to $smtp_server has failed!")); select(S); $| = 1; select(STDOUT); $DATA_IN = <S>; ($DATA_IN !~ /^220/) && (&error("data in Connect error - 220")); print S "HELO $ENV{REMOTE_HOST}\r\n"; $DATA_IN = <S>; ($DATA_IN !~ /^250/) && (&error("data in Connect error - 250")); print S "MAIL FROM:<$emailfrom>\n"; $DATA_IN = <S>; ($DATA_IN !~ /^250/) && (&error("'From' address not valid")); print S "RCPT TO:<$recipient>\n"; $DATA_IN = <S>; ($DATA_IN !~ /^250/) && (&error("'Recipient' address not valid")); print S "DATA\n"; $DATA_IN = <S>; ($DATA_IN !~ /^354/) && (&error("Message send failed - 354")); print S <<MESSAGES; From: $emailfrom To: $recipient Subject: $subject $message . MESSAGES $DATA_IN = <S>; ($DATA_IN !~ /^250/) && (&error("Message send failed - try again - 250")); print S "QUIT\n"; print "Content-type: text/html\n\n"; print "<br>Email sucessfully sent\n"; } sub error { # Displays any errors and prints out FORM and ENV info. print "Content-type: text/html\n\n"; print "<PRE>\nCGI Error: $!\n"; print "Message: $_[0]\n\n"; print "\n Form Variables \n"; foreach $key (sort keys %in) { print "$key: \t$in{$key}\n"; } print "\n Environment Variables \n"; foreach $env (sort keys %ENV) { print "$env: \t$ENV{$env}\n"; } print "\n</PRE>"; exit; } Now with the module Net::SMTP you need only to place lines of code to access the subs in the module just like those who are able to use sendmail. The advantage of sending directly through sockets I believe would be speed. Your program would not have to go through another program(i.e. sendmail) to get your email sent. However as you can see there is more code to be written. Now I am in no way an expert on this so don't take what I have said as law. I may be wrong or only partially right. Still learning all this myself.
|