IMAP Debug - Yash-777/Java_Mail GitHub Wiki
From my point of view these are Some of the following scenarios where the server is not accessible:
- We need to check the CLIENT/USERS machines inbound and outbound ports and IP’s are enabled/added.
- Form Client Machine Use PortQuery to check IP with Port is accessible or not.
- Last Check We need to check the outside access is enabled or not from Mail Server Side.
// https://mvnrepository.com/artifact/com.sun.mail/javax.mail/1.6.1
public class JavaIMAPTest {
public static void main(String[] args) throws Exception {
// configure the jvm to use the jsse security.
java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
//pop3Test(username, password);
imapTest("outlook.office365.com", "[email protected]", "Password2017", 993);
}
static String protocol = "IMAP";
public static void imapTest2(String server, String username, String password, int port) throws Exception {
Properties props = new Properties();
// set this session up to use SSL for IMAP connections
props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
// don't fallback to normal IMAP connections on failure.
props.setProperty("mail.imap.socketFactory.fallback", "false");
// use the simap port for imap/ssl connections.
props.setProperty("mail.imap.socketFactory.port", port + "");
props.setProperty("mail.imap.partialfetch", "false");
props.setProperty("mail.imap.auth.plain.disable", "true");
props.setProperty("mail.imaps.auth.plain.disable", "true");
Session session = Session.getInstance(props);
session.setDebug(true);
Store store = session.getStore(protocol.toLowerCase());
System.out.println("Connecting Store with --Server:" + server + " port:" + port + " username:" + username);
store.connect(server, port, username, password);
if (store.isConnected()) {
System.out.println("Imap store connected*****************");
}
System.out.println("Connect Succeed");
}
public static void imapTest(String server, String username, String password, int port) throws Exception {
// Connect to the server
// Session session = Session.getDefaultInstance(props, null);
Properties properties = new Properties();
properties = System.getProperties();
properties.setProperty("mail.debug.auth ", "true");
properties.setProperty("mail.imaps.starttls.enable", "true");
// set this session up to use SSL for IMAP connections
properties.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
// don't fallback to normal IMAP connections on failure.
properties.setProperty("mail.imaps.socketFactory.fallback", "false");
// use the simap port for imap/ssl connections.
properties.setProperty("mail.imaps.socketFactory.port", port + "");
properties.setProperty("mail.imaps.auth.plain.disable", "true");
properties.setProperty("mail.imaps.auth.ntlm.disable", "true");
// properties.setProperty("mail.imaps.auth.gssapi.disable", "true");
//properties.setProperty("mail.imaps.auth.login.disable", "false");
properties.setProperty("mail.debug", "true");
/*Session session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});*/
Session session1 = Session.getInstance(properties, null);
Store store1 = session1.getStore("imaps");
// store1.connect();
store1.connect(server, username, password);
if (store1.isConnected()) {
System.out.println("*******************imap store connected*****************");
}
}
private static void pop3Test(final String username, final String password) throws Exception {
Properties props = new Properties();
final String HOST = "outlook.office365.com";
final String PROTOCOL = "pop3";
final String PORT = "995";
final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
props.setProperty("mail.pop3.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.pop3.socketFactory.fallback", "false");
props.setProperty("mail.pop3.port", PORT);
props.setProperty("mail.pop3.socketFactory.port", PORT);
URLName urln = new URLName(PROTOCOL, HOST, Integer.parseInt(PORT), null, username, password);
//Session session = Session.getInstance(props, null);
//Store store = session.getStore(urln);
//store.connect();
Session session = Session.getInstance(props, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
Store store = session.getStore("pop3s");
store.connect();
if (store.isConnected()) {
System.out.println("*******************pop3 store connected*****************");
}
}
}
/*
DEBUG: JavaMail version 1.6.1
DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
DEBUG: Tables of loaded providers
DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
DEBUG: getProvider() returning javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle]
DEBUG IMAPS: mail.imap.fetchsize: 16384
DEBUG IMAPS: mail.imap.ignorebodystructuresize: false
DEBUG IMAPS: mail.imap.statuscachetimeout: 1000
DEBUG IMAPS: mail.imap.appendbuffersize: -1
DEBUG IMAPS: mail.imap.minidletime: 10
DEBUG IMAPS: enable STARTTLS
DEBUG IMAPS: closeFoldersOnStoreFailure
DEBUG IMAPS: trying to connect to host "outlook.office365.com", port 993, isSSL true
* OK The Microsoft Exchange IMAP4 service is ready. [QQBNADYAUABSADEAMABDAEEAMAAwADkANwAuAEUAVQBSAFAAUgBEADEAMAAuAFAAUgBPAEQALgBPAFUAVABMAE8ATwBLAC4AQwBPAE0A]
B0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
B0 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: protocolConnect login, host=outlook.office365.com, [email protected], password=<non-null>
DEBUG IMAPS: mechanism PLAIN disabled by property: mail.imaps.auth.plain.disable
DEBUG IMAPS: mechanism LOGIN not supported by server
DEBUG IMAPS: mechanism NTLM disabled by property: mail.imaps.auth.ntlm.disable
DEBUG IMAPS: mechanism XOAUTH2 disabled by property: mail.imaps.auth.xoauth2.disable
DEBUG IMAPS: LOGIN command trace suppressed
DEBUG IMAPS: LOGIN command result: B1 OK LOGIN completed.
B2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
B2 OK CAPABILITY completed.
DEBUG IMAPS: AUTH: PLAIN
DEBUG IMAPS: AUTH: XOAUTH2
DEBUG IMAPS: IMAPProtocol noop
B3 NOOP
B3 OK NOOP completed.
*******************imap store connected*****************
DEBUG: setDebug: JavaMail version 1.6.1
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
DEBUG IMAP: mail.imap.partialfetch: false
DEBUG IMAP: mail.imap.ignorebodystructuresize: false
DEBUG IMAP: mail.imap.statuscachetimeout: 1000
DEBUG IMAP: mail.imap.appendbuffersize: -1
DEBUG IMAP: mail.imap.minidletime: 10
DEBUG IMAP: closeFoldersOnStoreFailure
Connecting Store with --Server:outlook.office365.com port:993 username:[email protected]
DEBUG IMAP: trying to connect to host "outlook.office365.com", port 993, isSSL false
* OK The Microsoft Exchange IMAP4 service is ready. [QQBNADYAUABSADEAMABDAEEAMAAxADAANwAuAEUAVQBSAFAAUgBEADEAMAAuAFAAUgBPAEQALgBPAFUAVABMAE8ATwBLAC4AQwBPAE0A]
A0 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
A0 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: XOAUTH2
DEBUG IMAP: protocolConnect login, host=outlook.office365.com, [email protected], password=<non-null>
DEBUG IMAP: mechanism PLAIN disabled by property: mail.imap.auth.plain.disable
DEBUG IMAP: mechanism LOGIN not supported by server
DEBUG IMAP: mechanism NTLM not supported by server
DEBUG IMAP: mechanism XOAUTH2 disabled by property: mail.imap.auth.xoauth2.disable
DEBUG IMAP: LOGIN command trace suppressed
DEBUG IMAP: LOGIN command result: A1 OK LOGIN completed.
A2 CAPABILITY
* CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS MOVE ID UNSELECT CLIENTACCESSRULES CLIENTNETWORKPRESENCELOCATION BACKENDAUTHENTICATE CHILDREN IDLE NAMESPACE LITERAL+
A2 OK CAPABILITY completed.
DEBUG IMAP: AUTH: PLAIN
DEBUG IMAP: AUTH: XOAUTH2
DEBUG IMAP: IMAPProtocol noop
A3 NOOP
A3 OK NOOP completed.
Imap store connected*****************
Connect Succeed
*/