This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.



Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

error in fetching mail  RSS feed

 
gayathri murugesan
Ranch Hand
Posts: 32
  • 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);
}
}




Fetch.java:28: incompatible types
found : PopupAuthenticator
required: javax.mail.Authenticator
Authenticator auth = new PopupAuthenticator();
^
1 error

i m getting this error....please help..............



 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

Please edit your post to UseCodeTags. It's unnecessarily hard to read the code as it is, making it less likely that people will bother to do so.

If you look at their respective javadocs you will see that java.net.Authenticator has no direct relationship with javax.mail.Authenticator (which is what you should be using instead).

Also note that the array "pass" that the code uses is empty (the actual password is in the "password" variable).
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags.

Your imports are wrong; you are importing (and therefore extending) java.net.Authenticator but you should import (and therefore extend) javax.mail.Authenticator. This is annoying yes, two classes with both the same purpose in two different packages. The same problem with PasswordAuthentication. The major reason is that java.net.PasswordAuthentication uses the more secure* char[] for the password whereas javax.mail.PasswordAuthentication uses a String.

Now ideally, JavaMail would have used the classes in java.net but unfortunately this is not the case. Unless JavaMail predates Java 1.2 (which introduced java.net.Authenticator and java.net.PasswordAuthentication), I can see no valid reason for this. There is nothing we can change about it though...


* A String is immutable and therefore the password will remain in memory as long as the String remains in memory. If it gets put in the password pool that will be as long as the JVM is running. A char[] on the other hand can be modified; using Arrays.fill(array, '\0') the entire password can be erased from memory and replaced by '\0' characters.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Also note that the array "pass" that the code uses is empty (the actual password is in the "password" variable).

Indeed, see my reply in http://www.coderanch.com/t/475699/Other-JSE-JEE-APIs/java/help-me-retrieving-mail
 
gayathri murugesan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot...it worked... javascript:emoticon('');
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still trying to figure out how two different people could write the exact same code.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We're thinking colleagues or project partners.
 
gayathri murugesan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes..we are project partners.when we encountered this problem,we thought of seeking help.we got our doubts cleared separately.thanks for your help.we successfully started our project.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!