JavaMail: saving a Message, to send it later

A

Alberto Dell'Era

Alternative subject: inverse of Message.writeTo() ;-)

To send a MimeMessage in JavaMail, one simply uses

Transport.send (message);

I need to store the mail on the file system (in a database actually,
but that's not the problem, I know how to do that) and then, later,
read it back and send it.

Serializing "message" is not possible since my message is not
serializable.

My idea is to store the message this way:

FileOutputStream fos = new FileOutputStream ("mymail.raw");
message.writeTo (fos);
fos.close();

and later (in another JVM) do something like this:

FileInputStream fis = new FileInputStream ("mymail.raw");
message.READFROM (fis);
Transport.send (message);

Sadly READFROM does not actually exist ... may any good soul suggest
an implementation for it, or another way to accomplish the same goal ?

BTW The message is a multi-part one, containing attachments such as
PDFs.

Many thanks, at least for reading up to this point!
Alberto
 
G

GaryM

(e-mail address removed) (Alberto Dell'Era) wrote in
FileInputStream fis = new FileInputStream ("mymail.raw");
message.READFROM (fis);
Transport.send (message);

Sadly READFROM does not actually exist ... may any good soul
suggest an implementation for it, or another way to accomplish the
same goal ?

Yes you use the MimeMessage(Session, Inputstream) constructor. You can
do it all in that Transport.send method. Create a 'faux' session if
need to. Review the API Doc for MimeMessage, Alberto.

Best regards,

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top