【发布时间】:2013-06-22 03:59:04
【问题描述】:
在一个应用程序中,我使用 java 实现了邮件发送逻辑。我使用了smtp.gmail.com 而不是587 port 以及有效的gmail id 和密码。在开发环境中一切正常。但在生产环境中,我需要使用不同的邮件服务器,比如 smtp.xyz.in 而不是 port 25,并在该域上使用有效的电子邮件 ID 和密码。
当我继续使用以下代码启用 SSL 时:
我收到一个错误
Could not convert socket to TLS
SunCertPathBuilderException: Unable To Find Valid Certification Path To Requested Target
================================================ ========
final ResourceBundle rsbd=ResourceBundle.getBundle("main/ResourceBundle/Dyna");
// -- Attaching to default Session, or we could start a new one
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "true");
props.put("mail.smtp.port", port);
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.EnableSSL.enable","true");
Session session =Session.getInstance(props, new Authenticator() {protected PasswordAuthentication getPasswordAuthentication() {return new PasswordAuthentication(admin_mail, admin_password);}});
// -- Create a new message --
Message msg = new MimeMessage(session);
// -- Set the FROM and TO fields --
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(email, false));
msg.setSubject(subject);
msg.setText(emailContent);
// -- Set some other header information --
msg.setHeader("X-Mailer", "LOTONtechEmail");
msg.setSentDate(new Date());
// -- Send the message --
Transport.send(msg);
当我删除 EnableSSL 并尝试添加以下代码时:
(getting javax.mail.AuthenticationFailedException:535 5.7.3 Authentication unsuccessful)
================================================ =============================
props.put("mail.smtp.socketFactory.port","25");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "true");
MailSSLSocketFactory sf=new MailSSLSocketFactory();
sf.setTrustAllHosts(true);
props.put("mail.smtp.ssl.socketFactory", sf);
通过在过去 3 天内进行足够多的谷歌搜索,我了解到我需要配置受信任的证书,例如给定的 here。
但我想在不加密且不抢劫以启用 SSL 的情况下继续。有没有办法在不启用 SSL 的情况下通过我们自己的域通过 java 程序发送电子邮件。 任何帮助将不胜感激。
【问题讨论】:
-
错误
javax.mail.AuthenticationFailedException:535 5.7.3 Authentication unsuccessful表示您的密码/用户名不正确。此错误与 SSL 无关。 -
但我可以使用相同的电子邮件和密码访问和发送电子邮件。更多相同的逻辑是在我的工作系统中发送电子邮件,但在生产服务器中不工作(即在某些 Intranet 中的系统上)
-
您是否尝试使用您的用户名添加域?
domain/username -
假设域是 xyz.in,我使用的是 mail.smtp.host: smtp.xyz.in mail.smtp.port:25 和邮件地址 abc@xyz.in 一切都有效据我所知。有没有其他方法可以在不使用自己的域服务器启用 SSL 的情况下发送邮件?
-
我也遇到了同样的问题,这个话题可以帮到你:stackoverflow.com/questions/12743846/…
标签: java smtp jakarta-mail mailing