POP3和SMTP的介绍,和简单发送邮件

POP3 命令简介

什么是 POP3

POP3 (Post Office Protocol 3) 即邮局协议的第 3 个版本,它规定怎样将个人计算机连接到 Internet 的邮件服务器和下载电子邮件的电子协议。它是因特网电子邮件的 第一个离线协议标准, POP3 允许用户从服务器上把邮件存储到本地主机(即自己的计算机)上,同时删除保存在邮件服务器上的邮件,而POP3服务器则是遵循 POP3 协议的接收邮件服务器,用来接收电子邮件的。

POP3 命令

POP3 命令包括:
USER username 认证用户名
PASS password 认证密码认证,认证通过则状态转换
APOP name,digest 认可一种安全传输口令的办法,执行成功导致状态转换,请参见 RFC 1321 。
STAT 处理请求 server 回送邮箱统计资料,如邮件数、 邮件总字节数
UIDL n 处理 server 返回用于该指定邮件的唯一标识, 如果没有指定,返回所有的。
LIST n 处理 server 返回指定邮件的大小等
RETR n 处理 server 返回邮件的全部文本
DELE n 处理 server 标记删除,QUIT 命令执行时才真正删除
RSET 处理撤消所有的 DELE 命令
TOP n,m 处理 返回 n 号邮件的前 m 行内容,m 必须是自然数
NOOP 处理 server 返回一个肯定的响应
QUIT 希望结束会话。如果 server 处于"处理" 状态,则现在进入"更新"状态,删除那些标记成删除的邮件。
如果 server 处于"认可"状态,则结束会话时 server 不进入"更新"状态 。 

SMTP 命令简介

什么是 SMTP

SMTP (Simple Mail Transfer Protocol) : 电子邮件从客户机传输到服务器或从某一个服务器传输到另一个服务器使用的传输协议。SMTP 是请求/响应协议,命令和响应都是基于 ASCII 文本,并以 CR 和 LF 符结束。响应包括一个表示返回状态的三位数字代码。SMTP在 TCP 协议 25 端口监听连接请求。

什么是 ESMTP

ESMTP (Extended SMTP),顾名思义,扩展 SMTP 就是对标准 SMTP 协议进行的扩展。它与 SMTP 服务的区别仅仅是,使用 SMTP 发信不需要验证用户帐户,而用 ESMTP 发信时, 服务器会要求用户提供用户名和密码以便验证身份。验证之后的邮件发送过程与 SMTP 方式没有两样。

SMTP 命令

SMTP 命令
SMTP 命令包括:
HELO 向服务器标识用户身份。发送者能欺骗,说谎,但一般情况下服务器都能检测到。
EHLO 向服务器标识用户身份。发送者能欺骗,说谎,但一般情况下服务器都能检测到。
MAIL FROM 命令中指定的地址是发件人地址
RCPT TO 标识单个的邮件接收人;可有多个 RCPT TO;常在 MAIL 命令后面。
DATA 在单个或多个 RCPT 命令后,表示所有的邮件接收人已标识,并初始化数据传输,以 CRLF.CRLF 结束
VRFY 用于验证指定的用户/邮箱是否存在;由于安全方面的原因,服务器常禁止此命令
EXPN 验证给定的邮箱列表是否存在,扩充邮箱列表,也常被禁用
HELP 查询服务器支持什么命令
NOOP 无操作,服务器应响应 OK
RSET 重置会话,当前传输被取消
QUIT 结束会话

部分错误号介绍:

501  参数格式错误
502  命令不可实现
503  错误的命令序列
504  命令参数不可实现
211  系统状态或系统帮助响应
214  帮助信息
220  <domain>服务就绪
221  <domain>服务关闭
421  <domain>服务未就绪,关闭传输信道
250  要求的邮件操作完成
251  用户非本地,将转发向<forward-path>
450  要求的邮件操作未完成,邮箱不可用
550  要求的邮件操作未完成,邮箱不可用
451  放弃要求的操作;处理过程中出错
551  用户非本地,请尝试<forward-path>
452  系统存储不足,要求的操作未执行
552  过量的存储分配,要求的操作未执行
553  邮箱名不可用,要求的操作未执行
354  开始邮件输入,以"."结束
554  操作失败

 


发邮件测试: --------------------------------------------- @1: test APOP Login... faild! Rec: +OK POP3 Welcome to quarkmail server version 1.2.1 < 40.1177651276@mail.zj.com>

 

Cmd: APOP dbefa29ed14c15a9adbeddda215276fb

Rec: -ERR bad login (-17)

Cmd: QUIT

Rec: +OK Quit

@2: faint! test APOP Login again... Rec: +OK POP3 Welcome to quarkmail server version 1.2.1 <21.1177654165@mail.zj.com>

Cmd: APOP da70efea2d874426b7bd10c317b8d538

Rec:  -ERR bad login (-17)

Cmd: USER

Rec: +OK User name accepted, password please

Cmd: PASS a420384997c8a1a93d5a84046117c2aa    //ps:故意发个错误密码

Rec: -ERR password was wrong (-15)

Cmd: APOP da70efea2d874426b7bd10c317b8d538

Rec: -ERR incorrect state (-40)

Cmd: QUIT

Rec: +OK Quit

@3: send mail Rec: 220 zj.com ESMTP server (quarkmail server - version 1.2.1) ready at Thu, 26 Apr 2007 20:29:37 +0800

Cmd: HELO smtp.zj.com

Rec: 250 zj.com Hello smtp.zj.com

Cmd: EHLO

Rec: 250-zj.com Hello 250-SIZE 20971520 250-8BITMIME 250-PIPELINING 250-AUTH=LOGIN 250-AUTH LOGIN 250 HELP

Cmd: AUTH LOGIN

Rec: 334 VXNlcm5hbWU6

Cmd: ZmJ1Zw==

Rec: 334 UGFzc3dvcmQ6

Cmd: Base64(Password)

Rec: 235 Authentication successful.

Cmd: SEND FROM:<a@mail.com>

Rec: 250 Ok

Cmd: RCPT TO:<b@mail.com>

Rec: 250 Ok

Cmd: DATA

Rec: 354 Start mail input; end with <CRLF>.<CRLF>

Cmd: From:a@mail.com To:b@mail.com Subject:send by我的主题.啊 Date:Thursday, April 26, 2007 8:28:53 PM MIME-Version: 1.0 Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: base64 X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: FBugSoft smtp mail sender V1.000.000.000 X-MimeOLE: Produced By FBugSoft SmtpMailOLE V1.000.000.000

xOO6w6O6DQogICAgusO+w7K7vPshDQogICAgztJjb3chLLLiytTSu8/CoaMhDQoNCg0KDQoNCs7SsrvLtcHLoaM4IQ0K .

Rec: 250 OK S2197938AbXDZM3h message accepted

Cmd: QUIT

Rec: 221 zj.com Out

221 zj.com Out


附Base64编码原理:

    Base64 使用US-ASCII子集的64个字符,即大小写的26个英文字母,0-9,+,/。编码总是基于3个字符,每个字符用8位二进制表示,因此一共24位,再分为4四组,每组6位,表示一个Base64的值。如下: "A", "B", "C", "D", "E", "F", "G", "H", "I","J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i","j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "+", "/" Base64值为0就是A,为27的就是b。这样,每3个字符产生4位的Base64字符。如果被加密的字符串每3个一组,还剩1或2个字符,使用特殊字符"="补齐Base64的4字。如,编码只有2个字符“me”,m的ascii是109,e的是101,用二进制表示分别是01101101、01100101,连接起来就是0110110101100101,再按6位分为一组:011011、010110、010100(不足6位补0),分别ascii分别是27、22、20,即Base64值为bWU,Base64不足4字,用=补齐,因此bWU=就me的Base64值。

SMTP reply codes

Reply codes in numerical order
CodeMeaning
200(nonstandard success response, see rfc876)
211System status, or system help reply
214Help message
220Service ready
221Service closing transmission channel
250Requested mail action okay, completed
251User not local; will forward to
354Start mail input; end with .
421Service not available, closing transmission channel
450Requested mail action not taken: mailbox unavailable
451Requested action aborted: local error in processing
452Requested action not taken: insufficient system storage
500Syntax error, command unrecognised
501Syntax error in parameters or arguments
502Command not implemented
503Bad sequence of commands
504Command parameter not implemented
521does not accept mail (see rfc1846)
530Access denied (???a Sendmailism)
550Requested action not taken: mailbox unavailable
551User not local; please try
552Requested mail action aborted: exceeded storage allocation
553Requested action not taken: mailbox name not allowed
554Transaction failed
Reply codes grouped by command
CommandCodeDescription
connect
220Service ready
 421Service not available, closing transmission channel
HELO
250Requested mail action okay, completed
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 504Command parameter not implemented
 521does not accept mail [rfc1846]
 421Service not available, closing transmission channel
EHLO
250Requested mail action okay, completed
 550Not implemented
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 504Command parameter not implemented
 421Service not available, closing transmission channel
MAIL
250Requested mail action okay, completed
 552Requested mail action aborted: exceeded storage allocation
 451Requested action aborted: local error in processing
 452Requested action not taken: insufficient system storage
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 421Service not available, closing transmission channel
RCPT
250Requested mail action okay, completed
 251User not local; will forward to
 550Requested action not taken: mailbox unavailable
 551User not local; please try
 552Requested mail action aborted: exceeded storage allocation
 553Requested action not taken: mailbox name not allowed
 450Requested mail action not taken: mailbox unavailable
 451Requested action aborted: local error in processing
 452Requested action not taken: insufficient system storage
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 503Bad sequence of commands
 521does not accept mail [rfc1846]
 421Service not available, closing transmission channel
DATA
354Start mail input; end with .
 451Requested action aborted: local error in processing
 554Transaction failed
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 503Bad sequence of commands
 421Service not available, closing transmission channel
received data
 250Requested mail action okay, completed
 552Requested mail action aborted: exceeded storage allocation
 554Transaction failed
 451Requested action aborted: local error in processing
 452Requested action not taken: insufficient system storage
RSET
200(nonstandard success response, see rfc876)
 250Requested mail action okay, completed
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 504Command parameter not implemented
 421Service not available, closing transmission channel
SEND
250Requested mail action okay, completed
 552Requested mail action aborted: exceeded storage allocation
 451Requested action aborted: local error in processing
 452Requested action not taken: insufficient system storage
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 502Command not implemented
 421Service not available, closing transmission channel
SOML
250Requested mail action okay, completed
 552Requested mail action aborted: exceeded storage allocation
 451Requested action aborted: local error in processing
 452Requested action not taken: insufficient system storage
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 502Command not implemented
 421Service not available, closing transmission channel
SAML
250Requested mail action okay, completed
 552Requested mail action aborted: exceeded storage allocation
 451Requested action aborted: local error in processing
 452Requested action not taken: insufficient system storage
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 502Command not implemented
 421Service not available, closing transmission channel
VRFY
250Requested mail action okay, completed
 251User not local; will forward to
 550Requested action not taken: mailbox unavailable
 551User not local; please try
 553Requested action not taken: mailbox name not allowed
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 502Command not implemented
 504Command parameter not implemented
 421Service not available, closing transmission channel
EXPN
250Requested mail action okay, completed
 550Requested action not taken: mailbox unavailable
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 502Command not implemented
 504Command parameter not implemented
 421Service not available, closing transmission channel
HELP
211System status, or system help reply
 214Help message
 500Syntax error, command unrecognised
 501Syntax error in parameters or arguments
 502Command not implemented
 504Command parameter not implemented
 421Service not available, closing transmission channel
NOOP
200(nonstandard success response, see rfc876)
 250Requested mail action okay, completed
 500Syntax error, command unrecognised
 421Service not available, closing transmission channel
QUIT
221Service closing transmission channel
 500Syntax error, command unrecognised
TURN
250Requested mail action okay, completed
 502Command not implemented
 500Syntax error, command unrecognised
 503

Bad sequence of commands


我的站点:www.fbug.cn

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值