明天就要去学校了。。有点不舍,本来今天就要去的,因为玉林到合肥有票了,就改签到明天,因为学生票还省下了100。。。

本来昨晚要写的,但是陪女票看电影《小萝莉的猴神大叔》去了。。

废话不多说,这几天在学《计算机网络》,发现telnet其实是个很万能的东西,我曾对它的印象仅仅停留在远程控制,那时候在机房叫老师打开机房的网络,老师在cmd就用telnet远程控制来打开网络。

比如用telnet发送邮件,就可以深刻理解协议的含义:语义语法时序,以后socket编程的时候就知道怎么设计协议了,其实和设计指令差不多。

因为QQ邮箱加密传输了,不好测试,这里用139移动邮箱发送到QQ邮箱来测试。

注意退出telnet的话,先按CTRL+J,然后输入quit即可退出。

base64加密的话:

echo -n 待加密的内容 | base64

先看看发送图(smtp):
发邮件

再来看看收邮件的(pop3):

✘  ~/WorkSpace/Netcan_Web/blog/source/Timeline  telnet pop.139.com 110
Trying 221.176.9.169...
Connected to pop.mail.10086.cn.
Escape character is '^]'.
+OK richmail system v10(32d256c7d202533-1a2ff)
USER netcan
+OK
PASS xxxxxx
+OK login success
LIST
+OK
1 11481
2 20476
3 22995
4 17824
5 16520
6 48992
7 50115
8 51141
9 50336
10 18149
11 51062
12 12116
13 20278
14 26734
15 51260
16 21147
17 51499
18 11584
19 20796
20 12594
21 52576
22 16798
.
RETR 1
+OK
Received:from mail139@139.com (unknown[172.16.202.6])
    by rmoda-17132 (RichMail) with ODA id 42ec5409b9d04b8-050cc;
    Fri, 05 Sep 2014 21:25:36 +0800 (CST)
X-RM-TRANSID:42ec5409b9d04b8-050cc
From: =?gb2312?B?1tC5+tLGtq8xMznTys/k?= <mail139@139.com>
Message-ID: <744425079.27371409923191498.JavaMail.hadoop@q201-o06-9>
Subject: =?GB2312?B?1tC5+tLGtq/M4dDRo7rH68T6udjXorG+u/q6xQ==?=
=?GB2312?B?wuu1scewu7C30dPgtu6jrM/qx+nH67Xju/ey6b+0?=
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_2737_1393666244.1409923191496"
X-RICHINFO:CATEGORY:4326;PRODUCTOPERATIONMAIL:2001;SELFCLOSED:1;M:;TEMPLATELIST:2_4;MAILORDERID:141956;NOTIFYTYPE:14;ISMULTITEMPLATE:1;BUSSINESSID:1443;MJ:0;ISWAPNOTIFY:0;CHANNEL:30
X-TDZXINFO: ODACHANNEL:30;ODACATEGORY:4326
X-OP_RICHINFO_MAILTYPE:0
Date:
To:netcan

------=_Part_2737_1393666244.1409923191496
Content-Type: text/plain;charset="gbk"
Content-Transfer-Encoding: base64

oaHX8L60tcS/zbuno7pbsunT4LbuXWh0dHA6Ly93YXBtYWlsLjEwMDg2LmNuL2ahoQqhoczh0NHE
+qO6yta7+sno1sNDTVdBUL3TyOuju8H3wb+wtNbQufrSxravR1BSU7Hq17y8xsvjoaMKCQkJCQkJ
CQkKCQkJCQkJCQkKCQkJCQkJCQkKCQkJCQkJCQkKCQkJCQkJCQkKCQkJCQkJICAJIAkgCgkJCgkJ
CQkJCQkJCgkJCQkJCgkJCQkJCQkJCiAJCQkJCQkgICAJIAogICAgICAgICAJCQo=
------=_Part_2737_1393666244.1409923191496
Content-Type: text/html;charset="gbk"
Content-Transfer-Encoding: base64

PGh0bWw+PGhlYWQ+PHRpdGxlPqGhPC90aXRsZT48bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5
cGUiIGNvbnRlbnQ9InRleHQvaHRtbDsgY2hhcnNldD1nYjIzMTIiLz48L2hlYWQ+PGJvZHkgYmdj
b2xvcj0iI0ZGRkZGRiIgbGVmdG1hcmdpbj0iMCIgdG9wbWFyZ2luPSIwIiBtYXJnaW53aWR0aD0i
MCIgbWFyZ2luaGVpZ2h0PSIwIj48c3BhbiBzdHlsZT0iIGZvbnQ6MHB4LzBweCAny87M5Sc7IGRp
c3BsYXk6bm9uZTsiPtfwvrS1xL/Nu6ejuluy6dPgtu5dPGEgaHJlZj0iaHR0cDovL3dhcG1haWwu
MTAwODYuY24vZiIgdGFyZ2V0PSJfYmxhbmsiPmh0dHA6Ly93YXBtYWlsLjEwM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骤:

发邮件

  1. 使用telnet SMTP地址 端口连接
  2. 发送HELO 邮箱服务器名称
  3. 发送AUTH LOGIN进行登陆,第一次输入的是base64加密过的用户名,第二次是base64加密过的密码。
  4. 发送MAIL FROM: <xxx@xx.com>准备发邮件
  5. 发送RCPT TO: <xx@xx.com>指定目标邮箱地址
  6. 发送DATA开始输入邮件内容,一行用.结束。
  7. 发送QUIT退出

收邮件

  1. 使用telnet POP3地址 端口连接
  2. 发送USER 用户名进行登陆
  3. 发送PASS 密码确定登陆
  4. 发送LIST查看邮件列表
  5. 发送RETR 编号查看邮件信息
  6. 发送DELE 编号删除邮件
  7. 发送QUIT退出