小编pho*_*nix的帖子

javamail isSSL false 即使我在发送邮件时将 tls 设置为 True

我正在尝试使用 javamail 发送电子邮件。它在java应用程序中工作。但是当我在 Weblogic Web 应用程序中使用它时,我遇到了一些错误。

Properties props = new Properties();
props.setProperty("mail.transport.protocol", "SMTPS");
props.setProperty("mail.smtp.host", "msg.petrochina.com.cn");
props.setProperty("mail.smtp.port", "465");
props.setProperty("mail.smtp.auth", "true");
MailSSLSocketFactory sf = null;
try {
  sf = new MailSSLSocketFactory();
  sf.setTrustAllHosts(true);
} catch (GeneralSecurityException e1) {
  e1.printStackTrace();
}
props.put("mail.smtp.ssl.enable", "true");
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.fallback", "false");
props.put("mail.smtp.ssl.socketFactory", sf);
final Authenticator authenticator = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
    return new PasswordAuthentication("dqlhgysbj@petrochina.com.cn", "123456");
}
};

Session session = Session.getDefaultInstance(props, authenticator);
session.setDebug(true);
MimeMessage mimeMessage = new MimeMessage(session);
  mimeMessage.setFrom(new InternetAddress("dqlhgysbj@petrochina.com.cn","dqlhgys"));
  mimeMessage.addRecipient(Message.RecipientType.TO, new …
Run Code Online (Sandbox Code Playgroud)

java weblogic jakarta-mail

3
推荐指数
1
解决办法
7861
查看次数

标签 统计

jakarta-mail ×1

java ×1

weblogic ×1