gpt4 book ai didi

java - 使用 apache commons 电子邮件库出现错误必须先发出 starttls 命令。请帮忙

转载 作者:行者123 更新时间:2023-11-29 09:25:44 25 4
gpt4 key购买 nike

Email email = new SimpleEmail();
String authuser = "......@gmail.com";
String authpwd = "*******";
// Very Important, Don't use email.setAuthentication()
email.setSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd));
email.setDebug(true); // true if you want to debug
email.setHostName("smtp.gmail.com");

email.getMailSession().getProperties().put("mail.smtp.auth", "true");
email.getMailSession().getProperties().put("mail.debug", "true");
email.getMailSession().getProperties().put("mail.smtp.port", "587");
email.getMailSession().getProperties().put("mail.smtp.socketFactory.port", "587");
email.getMailSession().getProperties().put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
email.getMailSession().getProperties().put("mail.smtp.socketFactory.fallback", "false");
email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
email.setFrom("........@gmail.com", "SenderName");
email.setSubject("TestMail");
email.setMsg("This is a test mail?");
email.addTo(".............@gmail.com", "ToName");
email.setTLS(true);
email.send();

最佳答案

摆脱所有 email.getMailSession().getProperties() - 它们不是必需的,可能会污染设置。

然后删除设置端口的行。 (email.setSmtpPort(587);)

关于java - 使用 apache commons 电子邮件库出现错误必须先发出 starttls 命令。请帮忙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2132333/

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