无法连接到gmail store javax邮件api
几天后我就开始尝试使用javaxmailapi检索发送的电子邮件。使用的依赖项-无法连接到gmail store javax邮件api,java,api,jakarta-mail,ui-automation,Java,Api,Jakarta Mail,Ui Automation,几天后我就开始尝试使用javaxmailapi检索发送的电子邮件。使用的依赖项- javax.mail 我收到错误消息,如无法连接到存储区或尝试连接到存储区时连接超时。这是我的密码 public static void main(String[] args) throws IOException { String userName = "mncjhc@gmail.com"; String password = "ckjbc"; String subjectKeyword
javax.mail
我收到错误消息,如无法连接到存储区或尝试连接到存储区时连接超时。这是我的密码
public static void main(String[] args) throws IOException {
String userName = "mncjhc@gmail.com";
String password = "ckjbc";
String subjectKeyword = "New Registration – Successful";
String fromEmail = "djhgdd@gmail.com";
String bodySearchText = "You have successfully register to our services";
searchEmail(userName, password, subjectKeyword, fromEmail, bodySearchText);
}
public static void searchEmail(String userName, String password, final String subjectKeyword, final String fromEmail, final String bodySearchText) throws IOException {
Properties properties = new Properties();
boolean val = false;
// server setting
properties.put("mail.store.protocol", "imap");
properties.put("mail.imap.host", "imap.gmail.com");
properties.put("mail.imap.port", 143);
// SSL setting
properties.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.imap.ssl.enable", "true");
properties.setProperty("mail.imap.socketFactory.fallback", "false");
properties.setProperty("mail.imap.socketFactory.port", String.valueOf(143));
properties.put("mail.imaps.ssl.checkserveridentity", "false");
properties.put("mail.imaps.ssl.trust", "*");
properties.put("mail.imap.fetchsize", "519200");
properties.put("mail.imaps.connectiontimeout", 1000);
properties.put("mail.imaps.connectionpooltimeout", 1000);
properties.put("mail.imaps.onTimeout", 1000);
Session session = Session.getDefaultInstance(properties,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
userName, password);// Specify the Username and the PassWord
}
});
try {
// connects to the message store
Store store = session.getStore("imap");
store.connect("imap.gmail.com", Integer.parseInt("143"), userName, password);
System.out.println("Connected to Email server….");
// opens the inbox folder
Folder folderInbox = store.getFolder("INBOX");
folderInbox.open(Folder.READ_ONLY);
folderInbox.close(false);
store.close();
}
}
尝试将mail.imap.port更改为587或尝试@Ganesh Gudghe尝试587并获得javax.mail.MessaginException:无法识别的SSL消息,纯文本连接?;嵌套异常为:javax.net.ssl.SSLException:无法识别的ssl消息,纯文本连接?在com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:742)上,您可以尝试第二个链接javatpoint@Ganesh Gudghe。好的,我看到了带有检索电子邮件bt的帖子,它带有pop3。那么我应该从imap更改为pop3吗?尝试将mail.imap.port更改为587或尝试@Ganesh Gudghe尝试587并获得javax.mail.MessagineException:无法识别的SSL消息,纯文本连接?;嵌套异常为:javax.net.ssl.SSLException:无法识别的ssl消息,纯文本连接?在com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:742)上,您可以尝试第二个链接javatpoint@Ganesh Gudghe。好的,我看到了带有检索电子邮件bt的帖子,它带有pop3。那么我应该从imap改为pop3吗?