gpt4 book ai didi

java - 无法将套接字转换为 TLS

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:49:56 25 4
gpt4 key购买 nike

我正在尝试在 eclipse IDE 中使用 java servlet 发送电子邮件。这是我的代码。

    final String username = "******@gmail.com";
final String password = "******";

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
props.put("mail.smtp.ssl.trust", "smtpserver");

Session session1 = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});

try
{
if(result)
{

Message message = new MimeMessage(session1);
message.setFrom(new InternetAddress("******60@gmail.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email));

message.setSubject("Welcome To Our Bank");
message.setText("Dear "+custname+","
+"\n\n Your Account has been Created Successfully."
+"\n\n Your Account Details Are:"
+"\n User Id : "+userid+""
+"\n Account Number : "+accno+""
+"\n Login Password : "+passwd+""
+"\n Transaction Password : "+t_passwd+"");

Transport.send(message);
out.println("mail sent");
}
}
catch(MessagingException e)
{
out.println("Exception Caught : "+e);
}

这是执行后发生的异常。

捕获异常:javax.mail.MessagingException:无法将套接字转换为 TLS; 嵌套异常是: java.io.IOException:服务器不受信任:smtp.gmail.com

最佳答案

通过将“mail.smtp.ssl.trust”设置为“smtpserver”,您表示您只信任名为“smtpserver”的服务器。 “smtp.gmail.com”未命名为“smtpserver”。

关于java - 无法将套接字转换为 TLS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16632334/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com