Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

javax.mail.internet.MimeMessage REMOVE THE 'MESSAGE ID'

843789Dec 7 2009 — edited Dec 7 2009
I'm trying to work out how to remove the message ID from a simple email app because I want to use my own.
Using 'removeHeader' does not seem to work.(Plan was to the addHeader to put in custom message ID.

I note there is a 'getMessageID()' method, but does not appear to be a set equivalent.

Does anyone know how to do it?

Code produces headers.....
Date: Mon, 7 Dec 2009 13:55:46 +0000 (GMT)
From: ...
To: ...
Message-ID: <8889804.0.126...030.JavaMail....>
Subject: JavaMail hello world example
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class SendEmail
{
   public static void main(String [] args)
   {
	Properties props = new Properties();
    props.put("mail.smtp.host", "..target_mx..");
    props.put("mail.smtp.localhost", "my_helo_name");
	props.put("mail.from", "....co.uk");
	props.put("mail.smtp.reportsuccess", "true");
    Session session = Session.getInstance(props, null);

    try {
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom();
        msg.setRecipients(Message.RecipientType.TO,
                          ".....uk");
        msg.setSubject("JavaMail hello world example");
        msg.setSentDate(new Date());
        msg.setText("Hello, world!\n");
		//Try to remove the header Message-ID:
		msg.removeHeader("Message-ID");
        Transport.send(msg);
    } catch (MessagingException mex) {
        System.out.println("CATCH EXCEPTION " + mex);
    }
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 4 2010
Added on Dec 7 2009
10 comments
948 views