walt wrote:
Hi,
I am new to Perl and want to connect to an smtp server on port 25 and then
send it the helo, mail from:, rcpt to:, data, commands but I would also like
to evaluate the response from the smtp server.
Has anyone got a script or can point me in the right direction?
A simple example on how to work with sockets can be found here:
<http://www.osix.net/modules/article/?id=441>
(just google for: perl io::socket tutorial)
As for the protocol, Wikipedia has a good article on that, look
especially at the included example:
<http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol#SMTP_transport_example>
You should really also have a look at the official documentation of SMTP:
<http://www.faqs.org/rfcs/rfc821.html>
And yes, i know RFC821 is deprecated, and there are newer, more
complicated, more feature-rich versions of the protocol available. But i
have yet to find a server that doesn't understand the basics layed out
in this specification.
BTW, re-implementing the client-side part of the SMTP protocol - while
not very usefull because there are tested modules around - is in my
opinion a very good practice for beginners. The protocol's design is
clean. The minimum requirements to get a working module are just that:
minimal. And getting a test server up and running is rather simple:
Most Linux/Unix distros already run some SMTP server on localhost, so
you can deliver mails to local users the moment to finished setting up
your machine[1][2].
LG
Rene
[1] If it doesn't work by default, look in the docs of your OS. You
probably only have to enable the sendmail service or something like that.
[2] Tested on Ubuntu 9.10:
ca...@plunger:~$ telnet localhost 25
Trying ::1...
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 plunger ESMTP Exim 4.69 Wed, 31 Mar 2010 17:18:06 +0200
HELO localhost
250 plunger Hello localhost [127.0.0.1]
MAIL FROM: ca...@localhost
250 OK
RCPT TO: ca...@localhost
250 Accepted
DATA
354 Enter message, ending with "." on a line by itself
Subject: This is a test mail
Yada? Yadayadayada!
Foo? No Bar!!!
.
250 OK id=1Nwzgt-0006JL-0Y
quit
221 plunger closing connection
Connection closed by foreign host.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/