views:

82

answers:

0

How can I store the messages which I've written through javamail into MySql table? I already configured james server config file to connect to mysql server(with datasource element name maildb), and I changed the element in James server config file to

 <inboxRepository>
            <repository destinationURL="db://maildb/spammer/"
   type="MAIL"/>      
    </inboxRepository>

but still I'm not able to read the messages through inboxes column of spammer table of mail database in MySql.

Here's my javamail class:

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class mail{

public static void main(String[] argts){







        String to = "red@localhost";



        String from = "blue@localhost";
        String subject = "jdk";
        String body = "Down to wind";

        if ((from != null) && (to != null) && (subject != null)  && (body != null)) // we have mail to send
        {

        try {




        Properties props = new Properties();

   props.put("mail.host", "127.0.0.1 ");
   props.put("mail.smtp.auth","true");

  Session  session = Session.getInstance(props, new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("blue", "blue");
}
});





            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
   Address[] add={ new InternetAddress(to) };
            message.setRecipients(Message.RecipientType.TO,add);
            message.setSubject(subject);
            message.setContent(body, "text/plain");
            message.setText(body);
            Transport.send(message);


            System.out.println("<b>Thank you.  Your message to " + to + " was successfully sent.</b>");






        } catch (Throwable t) {
           t.printStackTrace();
        }


        }

    }




}

What's wrong I'm doing here, and how can I read the message from spammer table in MySql?