Reputation: 1435
So i want to know whether an organisation can use or not SMTP protocol for Receiving Emails from Exchange server. As i read, The Standard for Receiving are POP3
or IMAP
, and the SMTP
Protocol is standard for Sending.
My Question is just whether it is possible to use SMTP
as Incoming Protocol .
If Yes, Then i want to know how will i read its messages using JavaMail API.
I am trying the following code. but getting NoSuchProviderException
private void fetch(String incomingHost, String username, String password) {
try {
Properties properties = new Properties();
properties.put("mail.store.protocol", "smtp");
properties.put("mail.smtp.host", incomingHost);
properties.put("mail.smtp.port", 25);
properties.put("mail.smtp.starttls.enable", false);
emailSession = Session.getInstance(properties);
Store store = emailSession.getStore();
store.connect(incomingHost, 25, username, password);
// create the folder object and open it
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_ONLY);
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
Message[] messages = emailFolder.getMessages();
System.out.println("messages.length---" + messages.length);
for (int i = 0; i < messages.length; i++) {
Message message = messages[i];
System.out.println("---------------------------------" + message.getDescription());
//writePart(message);
String line = reader.readLine();
if ("YES".equals(line)) {
message.writeTo(System.out);
} else if ("QUIT".equals(line)) {
break;
}
}
// close the store and folder objects
emailFolder.close(false);
store.close();
} catch (javax.mail.NoSuchProviderException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 0
Views: 363
Reputation: 29971
The simple answer is "no", but stackoverflow requires me to add all these words to make the answer long enough.
Upvotes: 1