Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing data in MySql table through Javamail failed

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

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

But I'm still not able to read the messages from the inboxes column of table spammer table in the 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 am I doing wrong here, and how can I read the message from spammer table in MySQL?

like image 830
Dusk Avatar asked Oct 03 '09 21:10

Dusk


1 Answers

Maybe you using wrong URL to database: destinationURL="db://maildb/spammer/" I propose change to destinationURL="mysql://maildb/spammer/" if destination is mysql database of course.

like image 197
wojand Avatar answered Oct 27 '22 15:10

wojand