Re: Bug: duplicate message ids

Boris Folgmann <[email protected]> Thu, 26 Apr 2007 14:55:50 +0200
Newsgroups gmane.comp.java.classpath.extensions.javamail
Message-ID <[email protected]>
Hi,

Chris Burdess schrieb/wrote:
> to create and send the messages? You're not reusing MimeMessage  
> object instances?

Yes, log4j does it! msg is a member variable of SMTPAppender.
They initialize it once when the log4j user calls activateOptions() which 
has to be done after setting all options on the appender but before 
starting to log. See source below.

Our webapp also sends mail by itself, but doesn't reuse the MimeMessage 
objects. Our message ids are unique, so your guess was right!
Our code is old, but IIRC think we've chosen to use local MimeMessage 
objects so that the application scales well, since it's multi-threaded. But 
is there also a restriction in the JavaMail specification, that is violated 
by log4j by reusing the MimeMessage object?

If not, I suppose that Transport.send() should set the message id on each call.

Here's their code:

   /**
      Activate the specified options, such as the smtp host, the
      recipient, from, etc. */
   public
   void activateOptions() {
     Properties props = new Properties (System.getProperties());
     if (smtpHost != null)
       props.put("mail.smtp.host", smtpHost);


     Session session = Session.getInstance(props, null);
     //session.setDebug(true);
     msg = new MimeMessage(session);

      try {
        if (from != null)
	 msg.setFrom(getAddress(from));
        else
	 msg.setFrom();

        msg.setRecipients(Message.RecipientType.TO, parseAddress(to));
        if(subject != null)
	 msg.setSubject(subject);
      } catch(MessagingException e) {
        LogLog.error("Could not activate SMTPAppender options.", e );
      }
   }

cu,
	boris