2011-08-25 178 views
3

我正在使用OpenSSL連接到郵件服務器。 如果你使用pop3 - 一切正常。如何正確連接使用AUTHENTICATE PLAIN的IMAP?

但是,我有IMAP工作的麻煩。 當我使用CAPABILITY命令 - 服務器返回我時,它支持:PLAIN,NTLM,GSS-API方法進行身份驗證。

我想使用PLAIN,因爲它比其他人更容易... 我已閱讀,它需要使用它。

我已經運行下一個版本,但沒有成功: ?登錄用戶通行證 ?登錄用戶通行證 ?登錄用戶通行證

我在做什麼錯?

請給一個忠告,

問候

回答

-1

?登錄[email protected]輸入mypassword \ r \ n

常常服務器不需要「@ box.zone」部分,你可以只輸入登錄

+3

你知道嗎?你是否與OP一樣?我的意思是,你回答了一個6個月的問題,用問題中甚至沒有討論過的答案元素,並在2分鐘內得到接受......如果這是正確的答案,我完全不介意,但它似乎只是從哪裏冒出來的。 – Bruno

+0

用戶名是「mymailbox」還是「mymailbox @ domain」純粹是服務器端的管理/實現決定。對於服務器管理員來說,當同一臺服務器用於多個域時,它們對於使其用戶名成爲完整的電子郵件地址很有用。 – Bruno

2
May be this will help 

/* RFC 4616.2. PLAIN SASL Mechanism.     
The mechanism consists of a single message, a string of [UTF-8] 
encoded [Unicode] characters, from the client to the server. The 
client presents the authorization identity (identity to act as), 
followed by a NUL (U+0000) character, followed by the authentication 
identity (identity whose password will be used), followed by a NUL 
(U+0000) character, followed by the clear-text password. As with 
other SASL mechanisms, the client does not provide an authorization 
identity when it wishes the server to derive an identity from the 
credentials and use that as the authorization identity. 

message = [authzid] UTF8NUL authcid UTF8NUL passwd 

Example: 
C: a002 AUTHENTICATE "PLAIN" 
S: + "" 
C: {21} 
C: <NUL>tim<NUL>tanstaaftanstaaf 
S: a002 OK "Authenticated" 
*/ 


IMAP not easy to code, literal string and xxx response formats ... . 
It's easier to use some free IMAP client. 
21

沒有對以前的答案居然說如何使用PLAIN身份驗證,所以我做了更多的挖掘。事實證明,認證信息預計在base64中。這可能是最容易解釋的例子。假設用戶名爲「bob」,密碼爲「munchkin」。

我們首先需要用base64編碼。在一個Linux-ish系統上,它喜歡這樣的:

echo -en "\0bob\0munchkin" | base64 

這根據需要合併空字符,也base64編碼。我們得到這個字符串:AGJvYgBtdW5jaGtpbg==

現在,我們可以做實際的認證(S =服務器,C =客戶端):

S: * OK The Microsoft Exchange IMAP4 service is ready. 
C: D0 CAPABILITY 
S: * CAPABILITY IMAP4 IMAP4rev1 AUTH=NTLM AUTH=GSSAPI AUTH=PLAIN CHILDREN IDLE NAMESPACE LITERAL+ 
S: D0 OK CAPABILITY completed. 
C: D1 AUTHENTICATE PLAIN 
S: + 
C: AGJvYgBtdW5jaGtpbg== 
S: D1 OK AUTHENTICATE completed 

大功告成!