【问题标题】:How to connect IMAP using AUTHENTICATE PLAIN correctly?如何正确使用 AUTHENTICATE PLAIN 连接 IMAP?
【发布时间】:2011-11-03 18:17:51
【问题描述】:

我正在使用 OpenSSL 连接到邮件服务器。

POP3 工作正常,但 IMAP 有问题。基于 CAPABILITY 命令服务器支持 PLAIN、NTLM 和 GSS-API 身份验证方法。

我想使用 PLAIN,因为它比其他人更容易。 我已经读过它需要使用<NUL>

我已经运行了下一个变体,但没有成功:

? login user pass
? login <nul>user<nul>pass
? <nul>login <nul>user<nul>pass

我做错了什么?

【问题讨论】:

    标签: imap


    【解决方案1】:

    之前的答案都没有真正说明如何使用 PLAIN 身份验证,所以我做了更多的挖掘。事实证明,在 base64 中需要身份验证信息。通过例子来解释可能是最容易的。假设用户名“bob”和密码“munchkin”。

    我们首先需要使用 base64 进行编码。在 Linux 系统上,它是这样的:

    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
    

    你就完成了!

    【讨论】:

    【解决方案2】:

    ?登录 mymailbox@box.zone 我的密码\r\n

    服务器通常不需要“@box.zone”部分,您只需输入登录即可

    【讨论】:

    • 你认识还是和OP是同一个人?我的意思是,你回答了一个 6 个月大的问题,使用了问题中甚至没有讨论过的答案元素,并且它在 2 分钟内被接受......我完全不介意它是否是正确的答案,但它似乎不知从何而来。
    • 用户名应该是mymailbox 还是mymailbox@domain 纯粹是服务器端的管理/实施决定。当同一台服务器用于多个域时,服务器管理员将其用户名设置为完整的电子邮件地址往往很有用。
    【解决方案3】:
    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 2015-02-09
      • 2023-04-08
      • 2019-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多