hweefarn has asked for the wisdom of the Perl Monks concerning the following question:
hi everybody :)
recently i am learning about perl socket programming. i found a tutorial and sample about using perl to send email (through socket). i try to run that script but not successful. then i try to debug it but there are something that i dont understand. so i decide to ask you all :)
here is part of the sample code that i dont understand:
use Socket; use strict; my($mailTo) = 'me@here'; my($mailServer) = 'host.there'; my($mailFrom) = 'me@here'; my($realName) = "Ralph Martin"; my($subject) = 'Test'; my($body) = "Test Line One.\nTest Line Two.\n"; $main::SIG{'INT'} = 'closeSocket'; my($proto) = getprotobyname("tcp") || 6; my($port) = getservbyname("SMTP", "tcp") || 25; my($serverAddr) = (gethostbyname($mailServer))[4]; if (! defined($length)) { die('gethostbyname failed.'); } socket(SMTP, AF_INET(), SOCK_STREAM(), $proto) or die("socket: $!"); $packFormat = 'S n a4 x8'; # Windows 95, SunOs 4.1+ #$packFormat = 'S n c4 x8'; # SunOs 5.4+ (Solaris 2) connect(SMTP, pack($packFormat, AF_INET(), $port, $serverAddr)) or die("connect: $!");
*****************************************************
i dont understand about $mailserver, $proto, $port, $serverAddr and $packFormat.
the explaination that i get from the web are as below, but i'm still abit confused.
-Initialize $mailServer which holds the symbolic name of your mail server.
-Get the protocol number for the tcp protocol and the port number for the smtp service. Recall: Windows 95 and NT do not implement the getprotobyname()or getservbyname() functions so default values are supplied.
-Initialize $serverAddr with the mail server's Internet address.
-Initialize $packedFormat with format specifiers.
my questions are:
1. is $mailserver means my computer name? or the hostname of the gateway of my LAN? or something like "smtp.streamyx.com"?
2. why do i need the tcp protocol? i want to send email, so i only need smtp, right?
3. is $serverAddr means the ip address of my pc? or the ip address of the gateway? or else?
4. what is $packedFormat means? it is for what?
that's all my questions. if u need more information about the scripts for sending email using socket, u can go to http://www.cs.cf.ac.uk/Dave/PERL/node180.html
ok, thank you very much :)
regards,
hweefarn
20031220 Edit by Corion: Changed formatted code to CODE tags
20031221 Edit by jeffa: Aliased email addresses
Back to
Seekers of Perl Wisdom