File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Problem using Java Mail API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Problem using Java Mail API" Watch "Problem using Java Mail API" New topic
Author

Problem using Java Mail API

King Chin
Greenhorn

Joined: Aug 13, 2008
Posts: 11
Hi All,

I used the below code to connect to Mail server of my Organization for accessing my mail box from Unix environment.

import javax.mail.*;
import java.sql.*;
import javax.mail.internet.*;
import java.util.*;

public class readm
{
public static void main(String args[]) throws MessagingException
{
//Properties props = new Properties();

Properties props =System.getProperties();
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imap");
store.connect("gwes.wide.corp.gwes.com", PORT,"user", "password");

}


I get the below error message even if I use 143 or 993 fot the PORT value in the code:

Exception in thread "main" javax.mail.MessagingException: Connection refused;
nested exception is:
java.net.ConnectException: Connection refused
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:571)
at javax.mail.Service.connect(Service.java:288)
at readm.main(readm.java:16)
Caused by: java.net.ConnectException: Connection refused
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(Unknown Source)
at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:107)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
... 2 more

I am able to send mails from Unix environment using the IMAP protocol.

Could any one please suggest me a solution for this?

Thanks
King Chin
Greenhorn

Joined: Aug 13, 2008
Posts: 11
I changed my port address to 25 and it throws the below exception:
Can any one please tell me what does it say:

DEBUG: setDebug: JavaMail version 1.4.1
DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Sun Microsystems, Inc]
DEBUG: mail.imap.fetchsize: 16384
220 gwes.wide.corp.gwes.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Thu, 4 Sep 2008 15:45:37 -0400
Exception in thread "main" javax.mail.MessagingException: 220 gwes.wide.corp.gwes.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Thu, 4 Sep 2008 15:45:37 -0400 ;
nested exception is:
com.sun.mail.iap.ConnectionException: 220 gwes.wide.corp.gwes.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Thu, 4 Sep 2008 15:45:37 -0400
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:569)
at javax.mail.Service.connect(Service.java:288)
at readm.main(readm.java:18)
Caused by: com.sun.mail.iap.ConnectionException: 220 gwes.wide.corp.gwes.com Microsoft ESMTP MAIL Service, Version: 6.0.3790.3959 ready at Thu, 4 Sep 2008 15:45:37 -0400
at com.sun.mail.imap.protocol.IMAPProtocol.processGreeting(IMAPProtocol.java:230)
at com.sun.mail.iap.Protocol.<init>(Protocol.java:114)
at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
... 2 more


Advance Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem using Java Mail API
 
Similar Threads
Reading Java Mail
Read emails from Microsoft Outlook Using Java Mail
unknown host exception error
Save email body content in a file on disk
error in retrieving mail through a proxy.