dcsimg
sending mail using james mail server
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ingenieur_info
Posted On:   Tuesday, April 28, 2009 11:40 AM

hi everybody, I'm new in using java mail, I have to send mail with james mail server using javamail. but when runnig my java project I have these errors: Exception in thread "main" javax.mail.MessagingException: Not connecteds at com.sun.mail.pop3.POP3Store.checkConnected(POP3Store.java:291) at com.sun.mail.pop3.POP3Store.getDefaultFolder(POP3Store.java:265) at MailClient.checkInbox(MailClient.java:64) at Test.main(Test.java:12) /**code of MailClient.java:**/ import java.io.*; import java.util.*; import javax.mail.*; import javax.mail.internet.*;    More>>


hi everybody,

I'm new in using java mail, I have to send mail with james
mail server using javamail. but when runnig my java project I have these errors:

Exception in thread "main" javax.mail.MessagingException:
Not connecteds

at
com.sun.mail.pop3.POP3Store.checkConnected(POP3Store.java:291)

at
com.sun.mail.pop3.POP3Store.getDefaultFolder(POP3Store.java:265)

at MailClient.checkInbox(MailClient.java:64)

at Test.main(Test.java:12)


/**code of MailClient.java:**/


import java.io.*;

import java.util.*;

import javax.mail.*;

import javax.mail.internet.*;


public class MailClient extends Authenticator

{
public static final int SHOW_MESSAGES = 1;

public static final int CLEAR_MESSAGES = 2;

public static final int SHOW_AND_CLEAR = SHOW_MESSAGES + CLEAR_MESSAGES;

protected String from;

protected Session session;

protected PasswordAuthentication authentication;


public MailClient(String user, String host)

{
this(user, host, false);

}

public MailClient(String user, String host, boolean debug)

{
from = user + '@' + host;

authentication = new PasswordAuthentication(user, user);

Properties props = new Properties();

props.put("mail.user", user);

props.put("mail.host", host);

props.put("mail.debug", debug ? "true" : "false");

props.put("mail.store.protocol", "pop3");

props.put("mail.transport.protocol", "smtp");

props.put("mail.smtp.port","25");

session = Session.getInstance(props, this);

}

public PasswordAuthentication getPasswordAuthentication()

{
return authentication;

}


public void checkInbox(int mode)

throws MessagingException, IOException

{
if (mode == 0) return;

boolean show = (mode & SHOW_MESSAGES) ;

boolean clear = (mode & CLEAR_MESSAGES) ;

String action =

(show ? "Show" : "") +

(show && clear ? " and " : "") +

(clear ? "Clear" : "");

System.out.println(action + " INBOX for " + from);

Store store = session.getStore();

Folder root = store.getDefaultFolder();

Folder inbox = root.getFolder("inbox");


inbox.open(Folder.READ_WRITE);


Message[] msgs = inbox.getMessages();

if (msgs.length == 0 && show)

{
System.out.println("No messages in inbox");

}
for (int i = 0; i < msgs.length; i++)

{
MimeMessage msg = (MimeMessage)msgs[i];

if (show)

{
System.out.println(" From: " + msg.getFrom()[0]);

System.out.println(" Subject: " + msg.getSubject());

System.out.println(" Content: " + msg.getContent());

}
if (clear)

{
msg.setFlag(Flags.Flag.DELETED, true);

}
}
inbox.close(true);

store.close();

System.out.println();

}

public void sendMessage(String to, String subject, String content) throws MessagingException

{
System.out.println("SENDING message from " + from + " to " + to);

System.out.println();

MimeMessage msg = new MimeMessage(session);

msg.addRecipients(Message.RecipientType.TO, to);

msg.setSubject(subject);

msg.setText(content);

Transport.send(msg);

}
}


code of test.java:

public class Test

{
public static void main(String[] args)throws Exception

{
// CREATE CLIENT INSTANCES


MailClient redClient = new
MailClient("red","localhost");

MailClient blueClient = new MailClient("blue", "localhost");

MailClient greenClient = new MailClient("green", "localhost");


// CLEAR EVERYBODY'S INBOX

redClient.checkInbox(MailClient.CLEAR_MESSAGES);

blueClient.checkInbox(MailClient.CLEAR_MESSAGES);

greenClient.checkInbox(MailClient.CLEAR_MESSAGES);

Thread.sleep(500); // Let the server catch up


// SEND A COUPLE OF MESSAGES TO BLUE (FROM RED AND GREEN)

redClient.sendMessage(

"green@localhost",

"Testing green from red",

"This is a test message");

greenClient.sendMessage(

"blue@localhost",

"Testing blue from green",

"This is a test message");

Thread.sleep(500); // Let the server catch up


// LIST MESSAGES FOR BLUE (EXPECT MESSAGES FROM RED AND GREEN)

blueClient.checkInbox(MailClient.SHOW_AND_CLEAR);

}

}


I search in google but still I have these errors.

can somebody please help me?

thanks.

   <<Less

Re: sending mail using james mail server

Posted By:   ingenieur_info  
Posted On:   Saturday, May 2, 2009 06:31 PM

hello,
finally i find the solution , its a problem of authentification on james .
About | Sitemap | Contact