I'm using apache commons smtp library to send email using my gmail account. Everything works ok , however the Message-Id header is sent and I'm looking to remove it(not sent it). Digging the net I found something on oracle documentation: http://www.oracle.com/technetwork/java/faq-135477.html#msgid
class MyMessage extends MimeMessage {
...
protected void updateMessageID() throws MessagingException {
setHeader("Message-ID", "my-message-id");
}
...
}
However I don't know how to implement this in apache commons.
Here is my code:
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
basically I need something like email.setMimeMessage(...)
, but there is not such a method, only email.getMimeMessage()
UPDATE - SOLUTION FOUND
public class MyEmail extends SimpleEmail{
protected MimeMessage createMimeMessage(Session aSession)
{
return new MyMessage(aSession);
}
}
You simply override createMimeMessage
method and make sure it returns you own MimeMessage
implementation( in this case MyMessage
)