| Home Profile Fun |
#110 Linux 03.04.2007
Example telnet ESMTP session with SMTP AUTHThis is an example session of a communication with a mailserver by using the shell and telnet. The mailserver uses ESMTP (Extended SMTP). In this example the server supports the authentication methods PLAIN and LOGIN, we will use LOGIN. The mailserver expects the data for the username and password base64 encoded. So the first step is to write a little perl script that does this encoding for us. I call it base64encoder.pl: #!/usr/bin/perl use MIME::Base64; # encode parameter 1 $encoded_usr = encode_base64($ARGV[0]); # encode parameter 2 $encoded_pwd = encode_base64($ARGV[1]); #$decoded = decode_base64($encoded); print $encoded_usr; print $encoded_pwd; The program needs two parameters, the username and the password. ./base64encoder.pl username password dXNlcm5hbWU= cGFzc3dvcmQ= Now we have the username and password base64 encoded so that we can start the session with the mailserver. If you don't have telnet installed try "nc mymailserver.com 25" (nc comes with the netcat package). # telnet mymailserver.com 25 Trying 80.100.11.133... Connected to mymailserver.com. Escape character is '^]'. 220 mymailserver.com ESMTP Postfix ehlo h1.home.net 250-mymailserver.com 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-STARTTLS 250-AUTH PLAIN LOGIN 250-AUTH=PLAIN LOGIN 250 8BITMIME auth login dXNlcm5hbWU= 334 UGFzc3dvcmQ6 cGFzc3dvcmQ= 235 Authentication successful mail from:<norbert@acodedb.com> 250 Ok rcpt to:<info@acodedb.com> 250 Ok data 354 End data with <CR><LF>.<CR><LF> from: name_of_sender <norbert@acodedb.com> to: name_of_recipient <info@acodedb.com> subject:test Enter the actual mailtext here...blabla. . 250 Ok: queued as 308EBE0575E7 quit 221 Bye Connection closed by foreign host. Explanation: All lines between "Escape character is '^]'." and "Connection closed by foreign host." beginning with digits are server responses. The other ones are the commands from the client. ehlo h1.home.netTells the server that the client is able to use the ESMTP protocol. The server responses with a list of available extensions which includes the login methods, here PLAIN and LOGIN. auth login dXNlcm5hbWU=Authenticate with the LOGIN method and the base64 encoded username. The server answer 'UGFzc3dvcmQ6' is base64 encoded for 'Password:'. Thus we enter the encoded password: cGFzc3dvcmQ= 354 End data with <CR><LF>.<CR><LF>The server tells us that we can finally send the mail by using a single '.' in the very last line of the mailtext. |