Forums Register Login

Problem using Java Mail API

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 4796 times.
Similar Threads
Reading Java Mail
unknown host exception error
Read emails from Microsoft Outlook Using Java Mail
error in retrieving mail through a proxy.
Save email body content in a file on disk
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 22:41:12.