Reputation: 1139
I am working in a company as an intern and everyone in the company uses outlook for mails. I couldn't figure out a way to read emails from the Inbox.
Let me give a view about my project. I am using JavaMail API for mails.
My first task - To send mails from java program using Reminder system, which I have successfully completed, by using the host, protocol, username and no password. There is no need of entering password, because if i try to enter the password it stopped working. Its working only without password.
so basically, I can send email using other employees in the company using there email address as "From" because there is no password need to be entered, possible only from java program.
My second task - To read the subject of the mail and the sender details and do some task...
There is no password to enter, but
Store store = session.getStore("smtp");
//I tried with imap, pop3, but everything gives error "No Such Provided"
store.connect("[email protected]", "PASSWORD");
store.connect() doesn't allow me to use the method without password.
The software will be using a new email address which is not the same address in users outlook but for testing I am using my email address first, because the software is going to be used by different users/computers.
If i try this way
session.getStore("imaps");
store.connect("host","username","password");
Error:
DEBUG: getProvider() returning
javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
DEBUG: mail.imap.statuscachetimeout: 1000
DEBUG: mail.imap.appendbuffersize: -1
DEBUG: mail.imap.minidletime: 10
DEBUG: trying to connect to host "host", port 993, isSSL true
javax.mail.MessagingException: Connection refused: connect;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:618)
at javax.mail.Service.connect(Service.java:291)
at javax.mail.Service.connect(Service.java:172)
at TestMail.InboxReader.main(InboxReader.java:52)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:570)
at
com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:284)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:227)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:109)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:585)
... 3 more
Java Result: 2
Upvotes: 0
Views: 3852
Reputation: 136
Use Exchange Web Services (EWS) API for seamless integration with Exchange Server. Quoting from MS site
EWS provides access to much of the same data that is made available through Microsoft Office Outlook.
EWS basics - http://msdn.microsoft.com/en-us/library/exchange/dd877045(v=exchg.140).aspx EWS Java API - http://archive.msdn.microsoft.com/ewsjavaapi
Upvotes: 1
Reputation: 29971
Need more details...
See the JavaMail FAQ and post the debug output when it fails. Also, the exact code you're using might be helpful.
You can test it all using code that comes with JavaMail, so you can determine whether the problem is in your code or something else. See the msgshow.java demo program included in the JavaMail download bundle.
Upvotes: 0