• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem using Java Mail API

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic