Thread: Javamail
View Single Post
  #1 (permalink)  
Old 04-16-2008, 05:20 AM
v_mallikarjun v_mallikarjun is offline
Member
 
Join Date: Apr 2008
Posts: 7
v_mallikarjun is on a distinguished road
Javamail
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.ConnectException: Connection refused: connect
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3St ore.java:161)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at mail.Test9.main(Test9.java:37)
Caused by: java.net.ConnectException: Connection refused: connect
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.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at com.sun.mail.util.SocketFetcher.createSocket(Socke tFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFe tcher.java:189)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:94 )
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java :214)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3St ore.java:157)
... 3 more


The above is the exception while executing connect statementfor the code given below, Can anyone help me out please my final year project end date is approaching





package mail;

import java.io.FileInputStream;
import java.util.Iterator;
import java.util.Properties;

import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Store;

public class Test9 {
public static void main(String[] args) {
Properties prop = new Properties();
FileInputStream file = null;

try{
int j = 0 ;
file = new FileInputStream("C:\\new\\MailProperties.txt");
prop.load(file);
Iterator it = prop.keySet().iterator();
String values[] = new String[5];
String keys[] = new String[5];
while(it.hasNext()) {
String key = (String)it.next();
String value = prop.getProperty(key);
keys[j] = key;
values[j] = value;
j++;
}
String host = values[1];
String username = values[2];
String password = values[0];
prop.put("mail.pop3.host", host);
Session session = Session.getDefaultInstance(prop, null);
Store store = session.getStore("pop3");
store.connect(host,username, password);
Folder folder = store.getFolder("Inbox.dbx");
folder.open(Folder.READ_ONLY);
Message message[] = folder.getMessages();
//Display from (only first) and subject of messages
for (int i=0, n=message.length; i<n; i++) {
System.out.println(i + ": "
+ message[i].getFrom()[0]
+ "\t" + message[i].getSubject());
System.out.println(message[i].getContent());
}
folder.close(false);
store.close();
} catch(Exception e) {
System.out.println(e);
}
}
}
Reply With Quote
Sponsored Links