0个
我正在尝试从Java连接到邮件服务器。我已经能够使用相同的代码成功地从Java连接到许多邮件服务器,包括Gmail、Rackspace、GoDaddy和其他,但是无论我尝试什么设置,这个都不起作用。
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", this.outgoingHost);
props.put("mail.smtp.port", 587);
props.put("mail.smtp.ssl.trust", this.outgoingHost);
session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
此操作失败,javax.mail.MessaginException:无法将套接字转换为TLS;嵌套异常为:javax.net.ssl.SSLException:无法识别的ssl消息,纯文本连接?
我也试过,,
props.put("mail.smtp.host", this.outgoingHost);
props.put("mail.smtp.port", 587);
props.put("mail.smtp.socketFactory.port", 587);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.ssl.trust", this.outgoingHost);
session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
此操作失败,javax.mail.SendFailedException:无效地址;嵌套异常为:com.sun.mail.smtp.SMTPAddressFailedException:在端口587上提交邮件需要550 smtp身份验证
我还尝试了端口465,但它超时了。
我能够使用雷鸟电子邮件客户端的相同smtp设置发送邮件(相同的主机/端口/用户/pw,但它必须做其他事情)。
使用JavaMail 1.51
有什么想法吗?
选中此链接以启用权限(如果发件人有谷歌电子邮件):
链接权限谷歌
未经许可,您不能从非谷歌开发的应用程序登录。
要登录,请仅使用邮件的域。例如:text@gmail.com -
使用SSL(smtps
)时,不使用STARTTLS(msa
),反之亦然。SSL默认为端口465
,TLS默认为端口587
。您可能还必须使用mail.smtp.SSL.protocols
或mail.smtps.SSL.protocols
设置SSL协议,以指定将为SSL/TLS连接启用的SSL协议。您最好避免覆盖PasswordAuthentication
以发送凭据,并使用SMTPTransport
connect
方法。另外,对于SSL,您必须为mail.transport.protocol
使用smtps
,并使用mail.smtps
道具,而不是mail.smtp
。我将提供SSL和TLS的示例。
您可以使用session.setDebug(true)
或props.put("mail.debug","true")
调试并查看控制台中的整个通信;这将非常有帮助,因为您将看到与服务器的整个telnet通信。
// Set debug so we see the whole communication with the server
props.put("mail.debug", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.host", outgoingHost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
// Enable STARTTLS
props.put("mail.smtp.starttls.enable", "true");
// Accept only TLS 1.1 and 1.2
props.setProperty("mail.smtp.ssl.protocols", "TLSv1.1 TLSv1.2");
Session session = Session.getInstance(props, null);
session.setDebug(true);
// Create an SMTP transport from the session
SMTPTransport t = (SMTPTransport)session.getTransport("smtp");
// Connect to the server using credentials
t.connect(outgoingHost, username, password);
// Send the message
t.sendMessage(msg, msg.getAllRecipients());
注意传输协议是smtp
DEBUG: JavaMail version 1.5.1
...
DEBUG: setDebug: JavaMail version 1.5.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "mail.example.com", port 587, isSSL false
220-srv.example.com ESMTP Exim 4.92 #2 Wed, 18 Mar 2020 15:55:56 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
DEBUG SMTP: connected to host "mail.example.com", port: 587
EHLO host.docker.internal
250-srv.example.com Hello ppp.home.provider.com [x.x.x.x]
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
STARTTLS
220 TLS go ahead
EHLO host.docker.internal
250-srv.example.com Hello ppp.home.provider.com [x.x.x.x]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<user@example.com>
250 OK
RCPT TO:<otheruser@mail.com>
250 Accepted
DEBUG SMTP: Verified Addresses
DEBUG SMTP: otheruser@mail.com
DATA
354 Enter message, ending with "." on a line by itself
Date: Wed, 18 Mar 2020 15:55:57 +0200 (EET)
From: user@example.com
To: otheruser@mail.com
Message-ID: <1899073220.0.1584539759931.JavaMail.user@mail.example.com>
Subject: Test from JAVA!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: smtpsend
Message from the JAVA app STARTTLS!
.
250 OK id=1jEZAt-009Y7x-5Z
Response: 250 OK id=1jEZAt-009Y7x-5Z
QUIT
221 srv.example.com closing connection
// Set debug so we see the whole communication with the server
props.put("mail.debug", "true");
// All mail props for protocol will be mail.smtps
// We set smtps transport protocol for SSL
props.put("mail.transport.protocol", "smtps");
props.put("mail.host", outgoingHost);
props.put("mail.smtps.auth", "true");
props.put("mail.smtps.port", "465");
props.put("mail.smtps.ssl.trust", outgoingHost);
props.put("mail.smtps.ssl.enable", "true");
// Accept only TLS 1.1 and 1.2
props.setProperty("mail.smtps.ssl.protocols", "TLSv1.1 TLSv1.2");
Session session = Session.getInstance(props, null);
session.setDebug(true);
// Create an SMTP transport from the session
SMTPTransport t = (SMTPTransport)session.getTransport("smtps");
// Connect to the server using credentials
t.connect(outgoingHost, username, password);
// Send the message
t.sendMessage(msg, msg.getAllRecipients());
注意TRANSPORT协议是smtps
DEBUG: JavaMail version 1.5.1
...
DEBUG: setDebug: JavaMail version 1.5.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "mail.example.com", port 465, isSSL true
220-srv.example.com ESMTP Exim 4.92 #2 Wed, 18 Mar 2020 16:09:51 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
DEBUG SMTP: connected to host "mail.example.com", port: 465
EHLO host.docker.internal
250-srv.example.com Hello ppp.home.provider.com [x.x.x.x]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "52428800"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate using mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
DEBUG SMTP: AUTH LOGIN command trace suppressed
DEBUG SMTP: AUTH LOGIN succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<user@example.com>
250 OK
RCPT TO:<otheruser@mail.com>
250 Accepted
DEBUG SMTP: Verified Addresses
DEBUG SMTP: otheruser@mail.com
DATA
354 Enter message, ending with "." on a line by itself
Date: Wed, 18 Mar 2020 16:09:50 +0200 (EET)
From: user@example.com
To: otheruser@mail.com
Message-ID: <1620303253.0.1584540592904.JavaMail.user@mail.example.com>
Subject: Test from JAVA!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: smtpsend
Message from the JAVA app SSL!
.
250 OK id=1jEZOK-009bbA-5C
Response: 250 OK id=1jEZOK-009bbA-5C
QUIT
221 srv.example.com closing connection
我正在尝试从我的java发送电子邮件,但我无法连接到我的主机。这里是我的代码: 这里是我的代码: 这里又是我的报告错误: 有人能帮帮我吗?:(
我试图理解Retheart文档的这部分内容,但无法理解:https://softinstigate.atlassian.net/wiki/spaces/rh/pages/9207828/installation+and+setup#installationandsetup-5.1connectreshearttomongodbovertls/ssl 使用keytool创建导入mongod使用的公共
几年前,我已经在Codeigniter(php)中实现了推送通知到我的项目中,直到10天前,一切都运行良好。我的文件在我的本地服务器以及在线通知工具上运行良好。 错误:"stream_socket_client():无法连接到ssl://gateway.push.apple.com:2195(连接拒绝)"。 我正在使用以下功能:
我正在尝试通过Gmail SMTP服务器使用JavaMail发送电子邮件。代码如下: 返回此错误: 无法将套接字转换为TLS; 完整的堆栈跟踪: 异常线程"main"javax.mail.RuntimeException:ervice.connectMessagingException:无法将套接字转换为TLS;嵌套异常是:ervice.java:176SSLHandshakeException:
我正在研究MQTT协议。我配置了它的服务器,并使用端口1883上的Mosquito库用java进行了通信。现在,我想让这种通信更加安全。据我所知,8883端口是为其基于tls的安全通信保留的。它需要X.509证书。为此,我找到了以下教程。 http://www.embedded101.com/Blogs/PaoloPatierno/entryid/366/mqtt-over-ssl-tls-wit
我正在尝试使用 javamail 连接到本地后缀鸽子服务器。我已经使用 Thunderbird 成功连接到服务器,所以我知道我的用户名和密码是正确的,但我总是得到 我所知道的唯一一件事就是改变java。禁用一些不太安全的协议。dovecot需要什么协议?还是我看错了方向。 如果这是一个协议问题,是否有任何方法可以将参数传递给编译器?我确实有其他服务,我想阻止支持禁用的协议 编辑: 这是我使用的代码