gpt4 book ai didi

JavaMail(smtps 和 imap)

转载 作者:行者123 更新时间:2023-12-02 08:20:47 24 4
gpt4 key购买 nike

如何配置 JavaMail 以使用 smtps 和 imap?

最佳答案

这是为了设置 SMTPS

private static Session createSession(String host, int port, boolean sslAuthenticationRequired, String userName, String password, boolean debug) {
Properties properties = new Properties();
String mailSmtp = "mail.smtp";

if (sslAuthenticationRequired) {
mailSmtp += "s";

properties.put(mailSmtp + ".socketFactory.port", Integer.toString(port));
properties.put(mailSmtp + ".socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.put(mailSmtp + ".socketFactory.fallback", "false");
}

properties.put("mail.debug", debug ? "true" : "false");
properties.put(mailSmtp + ".host", host);
properties.put(mailSmtp + ".user", userName);
properties.put(mailSmtp + ".password", password);
properties.put(mailSmtp + ".port", Integer.toString(port));
properties.put(mailSmtp + ".starttls.enable", "true");
properties.put(mailSmtp + ".auth", "true");

return Session.getDefaultInstance(properties, new PasswordAuthenticator(userName, password));
}

this link解释如何配置 IMAP。

关于JavaMail(smtps 和 imap),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5515410/

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