Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java Mail API problem

800320Sep 2 2008 — edited Sep 6 2008
I am writing a code to read mails in my Mailbox in Unix environment. Below is the code which I am using. I am not even able to connect to the server
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 tried changing the PORT as 143 and 993 but I always get the error message as below:


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

Here I am able to use the Mail API to send mails. Here is how I am establishing a session in my program to send mails.
   //Set the host smtp address
     Properties props = new Properties();
     props.put("mail.imap.host", "imap.jcom.net");

    // create some properties and get the default Session
    Session session = Session.getDefaultInstance(props, null);
    session.setDebug(debug);
Can any one please guide me in this ? I got the mail server name from the MS Outlook which I am using in my windows environment. I think the port number should not be a problem as either it should be 143 or 993 as it is imap protocol. Please help me in writing the program as I have very short time left to finish it.

Edited by: mannikavum on Sep 2, 2008 10:22 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 4 2008
Added on Sep 2 2008
10 comments
1,078 views