It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center。
9年前关闭。
如何配置JavaMail以使用smtps和imaps?
this link解释了如何配置IMAP。
9年前关闭。
如何配置JavaMail以使用smtps和imaps?
最佳答案
这是为了设置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。
关于java - JavaMail(smtps和imaps),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5515410/