问题描述
我正在尝试使用简单的Java程序(像这样).但是我的问题是:
I'm trying to connect to gmail using a simple java program (like this one). But my question is:
出于安全原因,当然可以使用加密密码而不是真实密码来执行此操作!!类似于我们在java-Oracle db中的工作方式?
Is there a way to do this with encrypted password and not the real password, for security reasons of course!! something like how we do in java-Oracle db ?
推荐答案
默认情况下,用于IMAP的唯一身份验证机制是 LOGIN
命令,该命令使用未加密的用户名和密码.您可以通过IMAP连接或通过STARTTLS
命令启动TLS层在其上添加加密层,但是仍然需要客户端知道明文密码.
By default, the only authentication mechanism for IMAP is the LOGIN
command, which takes an unencrypted username and password. You can add an encryption layer on top of it, either by connecting via IMAPs or starting a TLS layer via the STARTTLS
command, but it still requires the client to know the cleartext password.
服务器还可以选择提供通过 AUTHENTICATE
命令调用的SASL身份验证方法.服务器在响应CAPABILITY
命令时公布其支持的SASL机制.例如,如果服务器包含功能"AUTH=PLAIN
",则客户端可以通过AUTHENTICATE PLAIN
IMAP命令使用PLAIN
SASL身份验证方法.
A server can optionally also provide SASL authentication methods invokable via the AUTHENTICATE
command. The server advertises which SASL mechanisms it supports in its response to the CAPABILITY
command. For instance, if the server includes the capability "AUTH=PLAIN
", the client can use the PLAIN
SASL authentication method via the AUTHENTICATE PLAIN
IMAP command.
Gmail仅支持一种SASL身份验证机制,XOAUTH
:
Gmail supports only one SASL authentication mechanism, XOAUTH
:
C: 1 capability
S: * CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA XLIST CHILDREN XYZZY
SASL-IR AUTH=XOAUTH
S: 1 OK Thats all she wrote! dv32if2169247ibb.17
XOAUTH
是使用OAuth的非标准SASL身份验证机制. (前导X表示未标准化.)Google已发布定义XOAUTH
SASL机制.他们还提供了一个 google-mail-xoauth-tools包,其中包含示例代码,展示了如何通过XOAUTH
在Gmail中使用JavaMail.
XOAUTH
is a nonstandard SASL authentication mechanism using OAuth. (The leading 'X' means it's not standardized.) Google has published a document defining the XOAUTH
SASL mechanism. They've also provided a google-mail-xoauth-tools package, which includes sample code showing how to use JavaMail with Gmail via XOAUTH
.
这篇关于使用加密密码连接到gmail(使用imap和javamail)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!