Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to perl socket mail by hweefarn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (1)
As of 2023-09-26 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?