SMTP的相關命令

SMTP是Simple Mail Transfer Protocol的簡寫。 郵件是平常工做、生活中不能缺乏的一個工具,下面是郵件收發的流程。 Image 郵件的發送,主要是經過SMTP協議來實現的。SMTP協議最先在RFC 821(1982年)中定義,最後更新是在RFC 5321(2008年)中,更新中包含了擴展SMTP(ESMTP)。 在平時的程序開發中常常會有發送郵件的這種需求,因此免不了要對郵件發送服務器的可用性進行測試。下面是整理的命令,用來在命令行下測試SMTP服務器,進行郵件發送等操做,相信對於加深SMTP的理解能夠起到促進做用。 SMTP默認使用25端口,咱們可使用telnet工具進行測試。 一、鏈接SMTP服務器,查看是否存活。 >telnet smtp.sina.com 25 >Connected to mail.sina.com. >Escape character is '^]'. >220 smtp ready 在telnet下轉義符是Ctrol+],若是想退出,按轉義符後輸入quit,就能夠退回到命令行了。 二、用戶登錄 鏈接到服務器後,使用AUTH LOGIN命令進行用戶登錄(SMTP命令不區分大小寫) >auth login >334 VXNlcm5hbWU6 >c2VydmljZUBoZWVwLmNx >334 UGFzc3dvcmQ6 >xxxxxxxx >235 go ahead 235返回碼代表登錄驗證成功,用戶能夠進行後續的操做了。用戶郵箱和密碼是通過Base64編碼的,這個與服務器的安全特性相關,屬於可配置項。 三、發送郵件。 用戶身份驗證經過後,執行下面的命令進行郵件的發送。 >235 #2.0.0 OK Authenticated >MAIL FROM: yunpan001@sina.com >250 sender <yunpan001@sina.com> ok >RCPT to: cocowool@gmail.com >250 recipient <cocowool@gmail.com> ok >DATA >354 go ahead >Subject: Hi smtp mail >hello mail >. >250 ok: Message 1763097690 accepted SMTP命令列表 HELO 客戶端爲標識本身的身份而發送的命令(一般帶域名) EHLO 使服務器能夠代表本身支持擴展簡單郵件傳輸協議 (ESMTP) 命令。 MAIL FROM 標識郵件的發件人;以 MAIL FROM: 的形式使用。 RCPT TO 標識郵件的收件人;以 RCPT TO: 的形式使用。 TURN 容許客戶端和服務器交換角色,並在相反的方向發送郵件,而沒必要創建新的鏈接。 ATRN ATRN (Authenticated TURN) 命令能夠選擇將一個或多個域做爲參數。若是該會話已經過身份驗證,則ATRN 命令必定會被拒絕。 SIZE 提供一種使 SMTP 服務器能夠指出所支持的最大郵件大小的機制。兼容的服務器必須提供大小範圍,以指出能夠接受的最大郵件大小。客戶端發送的郵件不該大於服務器所指出的這一大小。 ETRN SMTP 的擴展。SMTP 服務器能夠發送 ETRN 以請求另外一臺服務器發送它所擁有的任何電子郵件。 PIPELINING 提供發送命令流(而無需在每一個命令以後都等待響應)的能力。 CHUNKING 替換 DATA 命令的 ESMTP 命令。該命令使 SMTP 主機沒必要持續地掃描數據的末尾,它發送帶參數的 BDAT 命令,該參數包含郵件的總字節數。接收方服務器計算郵件的字節數,若是郵件大小等於 BDAT 命令發送的值時,則該服務器假定它收到了所有的郵件數據。 DATA 客戶端發送的、用於啓動郵件內容傳輸的命令。 DSN 啓用傳遞狀態通知的 ESMTP 命令。 RSET 使整個郵件的處理無效,並重置緩衝區。 VRFY 確認在郵件傳遞過程當中可使用郵箱;例如,vrfy ted 確認在本地服務器上駐留 Ted 的郵箱。該命令在 Exchange 實現中默認關閉。 HELP 返回 SMTP 服務所支持的命令列表。 QUIT 終止會話。 SMTP命令響應碼 211 System status, or system help reply 214 Help message (Information on how to use the receiver or the meaning of a particular non-standard command; this reply is useful only to the human user) 220 Service ready 221 Service closing transmission channel 250 Requested mail action okay, completed 251 User not local; will forward to (See Section 3.4) 252 Cannot VRFY user, but will accept message and attempt delivery (See Section 3.5.3) 354 Start mail input; end with . 421 Service not available, closing transmission channel (This may be a reply to any command if the service knows it must shut down) 450 Requested mail action not taken: mailbox unavailable (e.g., mailbox busy or temporarily blocked for policy reasons) 451 Requested action aborted: local error in processing 452 Requested action not taken: insufficient system storage 455 Server unable to accommodate parameters 500 Syntax error, command unrecognized (This may include errors such as command line too long) 501 Syntax error in parameters or arguments502 Command not implemented (see Section 4.2.4) 503 Bad sequence of commands 504 Command parameter not implemented 550 Requested action not taken: mailbox unavailable (e.g., mailbox not found, no access, or command rejected for policy reasons) 551 User not local; please try (See Section 3.4) 552 Requested mail action aborted: exceeded storage allocation 553 Requested action not taken: mailbox name not allowed (e.g.,mailbox syntax incorrect) 554 Transaction failed (Or, in the case of a connection-opening response, "No SMTP service here") 555 MAIL FROM/RCPT TO parameters not recognized or not implemente 參考資料: 一、SMTP指令說明 二、SMTP百度百科 三、Wiki Smtp 四、RFC 5321 五、電子郵件收發原理和實現 六、Telnet下Smtp命令發送郵件 七、Send Mail Using Telnet 轉自——小狼的世界:原文連接《http://www.cnblogs.com/cocowool/archive/2012/03/14/2395390.html》html

相關文章
相關標籤/搜索