telnet实现通过可认证的smtp发送邮件
2009-04-11 00:39
1、得到用户名和密码的encode64编码(可通过下面的js取得)
2、telnet到smtp主机: [root@newsclub east]# telnet smtp.163.com 25 //登陆 smtp.163.com 端口号为 25 Trying 202.108.44.205... Connected to smtp.163.com (202.108.44.205). Escape character is '^]'. 220 163.com Coremail SMTP(Anti Spam) System HELO localhost // 与服务器打招呼,并告知客户端使用的机器名字,可以随便填写 250 OK AUTH LOGIN //使用身份认证登陆指令 334 dXNlcm5hbWU6 cmVkc29zMw== //输入已经base64_encode()过的用户名. 334 UGFzc3dvcmQ6 MbM2MDQ3NQ== //输入已经base64_encode()过的密码 235 Authentication successful MAIL FROM:<redsos3@163.com> //告诉服务器发信人的地址 250 Mail OK RCPT TO:<yourframe@21cn.com> //告诉服务器收信人的地址 250 Mail OK DATA //正面开始传输信件的内容,且最后要以只含有 . 的特殊行结束。 354 End data with <CR><LF>.<CR><LF> To:yourframe@21cn.com From:redsos3@163.com Subject:test mail From:redsos3@163.com test body . //结束传输信件 250 Mail OK queued as smtp14,F0CPBFsuzUOvoDwE.41582S2 QUIT //断开连接 221 Bye Connection closed by foreign host. 得到encode64编码: ========================================================================= <html> <head> <title>title1</title> <script language="javascript"> <!-- var keyStr = "ABCDEFGHIJKLMNOP" + "QRSTUVWXYZabcdef" + "ghijklmnopqrstuv" + "wxyz0123456789+/" + "="; function encode64(input) { input = escape(input); var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = ""; var i = 0; do { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4); chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = ""; } while (i < input.length); return output; } function decode64(input) { var output = ""; var chr1, chr2, chr3 = ""; var enc1, enc2, enc3, enc4 = ""; var i = 0; // remove all characters that are not A-Z, a-z, 0-9, +, /, or = var base64test = /[^A-Za-z0-9/+///=]/g; if (base64test.exec(input)) { alert("There were invalid base64 characters in the input text./n" + "Valid base64 characters are A-Z, a-z, 0-9, '+', '/', and '='/n" + "Expect errors in decoding."); } input = input.replace(/[^A-Za-z0-9/+///=]/g, ""); do { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } chr1 = chr2 = chr3 = ""; enc1 = enc2 = enc3 = enc4 = ""; } while (i < input.length); return unescape(output); } function doit() { myForm.eusername.value=encode64(myForm.username.value); myForm.epassword.value=encode64(myForm.password.value); } function dedoit() { myForm.username.value=decode64(myForm.eusername.value); myForm.password.value=decode64(myForm.epassword.value); } --> </script> </head> <body> <form name='myForm' action='login.html'> Username: <input type='text' name='username' value='yanhongbin1210'> Encode64 <input type='text' name='eusername'> <br/> Password: <input type='text' name='password' value='mypassword'> Encode64 <input type='text' name='epassword'><br/> <input type='button' value='encode64' onClick='doit()'> <input type='button' value='decode64' onClick='dedoit()'> </form> </body> </html> =========================================================================
一个例子:
220 163.com Anti-spam GT for Coremail System (163com[20081010])
HELO 163.com
AUTH LOGIN
eWFuaG9uZ2JpbjEyMTA=
Mjk2oTk0ng== (已替换)
MAIL FROM:<yanhongbin1210@163.com>
RCPT TO:<yanhongbin1210@163.com>
DATA
To:yanhongbin1210@163.com
From:yanhongbin1210@163.com
Subject:test mail
From:yanhongbin1210@163.com
test body
.
quit
250 OK
334 dXNlcm5hbWU6
535 Error: authentication failed
502 Error: command not implemented
502 Error: command not implemented
553 authentication is required,smtp8,DMCowLC7ch96Xt9JlnQTRA--.926S2 1239375514
503 bad sequence of commands
503 bad sequence of commands
421 closing transmission channel
C:/Documents and Settings/kevin>
|
转自:http://hi.baidu.com/afantihome/blog/item/a3b8d3cc5ecde91801e928e6.html