Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

help me in retrieving mail  RSS feed

 
shyamala thulasi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import javax.mail.*;
import javax.swing.*;
import java.util.*;
import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class PopupAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username, password;

String result = JOptionPane.showInputDialog("Enter 'username,password'");

StringTokenizer st = new StringTokenizer(result, ",");
username = st.nextToken();
password = st.nextToken();
char pass[]=new char[50];
return new PasswordAuthentication(username, pass);
}
}





import java.io.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.Authenticator;
import javax.mail.internet.*;


public class Fetch{
public static void main (String args[])
throws Exception {
String host = args[0];

// Get system properties
Properties props = System.getProperties();
props.put("mail.pop3.host", host);

// Setup authentication, get session
Authenticator auth = new PopupAuthenticator();
Session session =
Session.getDefaultInstance(props,auth);

// Get the store
Store store = session.getStore("pop3");
store.connect();

// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);

// Get directory
Message message[] = folder.getMessages();
for (int i=0, n=message.length; i<n; i++) {

System.out.println(i + ": "
+ message[i].getFrom()[0]
+ "\t" + message[i].getSubject());
String content =
message[i].getContent().toString();
if (content.length() > 200) {
content = content.substring(0, 200);
}
System.out.print(content);
}

// Close connection
folder.close(false);
store.close();
System.exit(0);
}
}



this is my code for retrieving mail.i m getting AUTHENTICATIONFAILEDEXCEPTION :EOF ON SOCKET.
PLEASE HELP ME.

 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags. You can edit your post to add them.

shyamala thulasi wrote:

You are ignoring the password the user entered, then create a new array which contains all '\0' characters. This is the C "end of string" character, and apparently JavaMail cannot handle it. I think you want this:
PLEASE HELP ME.

Keep it down.

Moving to Other JSE/JEE APIs since that is where we handle JavaMail.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!