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
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.