Feb
20
|
When using Javamail to send mail the Message-ID gets set when the message is actually sent. If you want to provide your own Message-ID then you need to subclass MimeMessage. You can then use that subclass to create your message.
public class CustomMimeMessage extends MimeMessage { public CustomMimeMessage(Session session) { super(session); } @Override protected void updateMessageID() throws MessagingException { setHeader("Message-ID", "objects-message-id"); } }
Array ( ) 2 Responses to “How to specify a custom Message-ID with Javamail”
Leave a Reply
You must be logged in to post a comment.
August 8th, 2010 at 5:36 pm
I have done this, however the message-ID I supply is not recognized when sending mail using Gmail – rather, Gmail apparently generates its own message-ID (when I use the default JavaMail message-ID, Gmail does recognize it). Any ideas why this is happening or how to solve it?
Thanx
January 8th, 2011 at 3:13 am
Hi David,
It’s been a long time since you posted your problem, but do you remember if the Message-ID you set – and that was not recognize by GMail – was well-formed?
I mean that the Message-ID must respect a certain pattern (similar to an e-mail address, cf. http://tools.ietf.org/html/rfc5322#section-3.6.4). Maybe it wasn’t the case with your custom ID and that was why GMail reject it?