Actually, MimeMessage
does not implement Serializable
by design, you can extend MimeMessage
to do so but you do not need to as MimeMessage
has facilities using writeTo(OutputStream) to allow you to save the content as n RFC-822 mime message.
try (OutputStream str = Files.newOutputStream(Paths.get("message.eml"))) {
msg.writeTo(str);
}
You can then read this message in for later processing using the MimeMessage(Session,InputStream) constructor with the session object.
Session session = Session.getInstance(props);
try (InputStream str = Files.newInputStream(Paths.get("message.eml"))) {
MimeMessage msg = new MimeMessage(session, str);
// Do something with the message, maybe send it.
Transport.send(msg);
}
If you happen to be using spring's JavaMailSender then you can also construct new mime messages through the configured session by using createMimeMessage(InputStream) which uses the configured session.