• Post Reply Bookmark Topic Watch Topic
  • New Topic

the authenticator cannot work?  RSS feed

Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have wirte a midlet which simply give 2 parameters (user & pwd) to the servlet which is for authenticating the user to retrieve his/her e-mail inbox account.
the coding is below:
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class ServletMailLogin extends HttpServlet{
String user,pwd;
public void doPost(HttpServletRequest req ,HttpServletResponse res) throws IOException, ServletException
PrintWriter out = res.getWriter();
user = req.getParameter("user");
pwd = req.getParameter("pwd");

Properties props = new Properties();
//place the authentication info in
// create an empty authenticator object
Authenticator auth = new SMTPAuthenticator();
// Get a session - pass auth object
Session session = Session.getDefaultInstance(props, auth);
Store store = session.getStore("smtp");
// do not pass any arguments to the connect method
Folder folder = store.getFolder("INBOX");
Message messages[] = folder.getMessages();
for (int i=0; i<messages.length; i++) {
out.print(i + ": " + messages[i].getFrom()[0] + "\t" + messages[i].getSubject() + "\t" + messages[i].getSentDate() + "\n\n");
catch (MessagingException me) {


private class SMTPAuthenticator extends javax.mail.Authenticator{
public PasswordAuthentication getPasswordAuthentication(){
String username,password;

username = ServletMailLogin.this.user;
password = ServletMailLogin.this.pwd;
return new PasswordAuthentication(username,password);
compliation is not problem but it will just return me a empty(not null!!) content to the emulator.
Can someone give me advice PLS??
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you call the servlet directly on Browser, its work fine?
Best Regards
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!