rzvika2
asked on
sending mail with attachment
Hi!
Can you help me with how to send using javax.mail (I'm using the spring of environment, but I'm not sure it matters) a mail with attachments.
I also want to have the ability so save the message (and its attached files) as a one byte array.
Thanks!
Can you help me with how to send using javax.mail (I'm using the spring of environment, but I'm not sure it matters) a mail with attachments.
I also want to have the ability so save the message (and its attached files) as a one byte array.
Thanks!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> I also want to have the ability so save the message (and its attached files) as a one byte array.
Do you have access to the mail server code?
Do you have access to the mail server code?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No, but you can assume that I create the message and know the file names and path.
I assume I can use serialization, but I don't want to...
I assume I can use serialization, but I don't want to...
> I also want to have the ability so save the message (and its attached files) as a one byte array.
I might have misunderstood your question, you obviously mean to save the message just before it leaves *your* mail server, don't you? Or do you mean to save the message on the receiving end mail server?
I might have misunderstood your question, you obviously mean to save the message just before it leaves *your* mail server, don't you? Or do you mean to save the message on the receiving end mail server?
ASKER
I have the MimeMessage object, for example, and I'm adding to it the MimeMultipart.
Now I want to save it to the DB as a byte array (BLOB) for persistency.
Now I want to save it to the DB as a byte array (BLOB) for persistency.
Ah I see, I thought you wanted to save it onto the hard disk. Are you using a prepared statement?
ASKER
the bottom line is that I need it as a byte array, the DB issue is not relevant.
Yes you do, you need a ByteArrayInputSTream, I just asked for a ps in order to post some sample code. I am assuming you indeed have a ps, then you can do:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
out = new ObjectOutputStream(<your multipart object here>) ;
out.writeObject(object);
out.close();
byte [] bytes = bos.toByteArray();
ps = con.prepareStatement("inse rt into mytable values ?");
ByteArrayInputStream bais = new ByteArrayInputStream(bytes );
ps.setBinaryStream(1, bais, bytes.length)
ByteArrayOutputStream bos = new ByteArrayOutputStream();
out = new ObjectOutputStream(<your multipart object here>) ;
out.writeObject(object);
out.close();
byte [] bytes = bos.toByteArray();
ps = con.prepareStatement("inse
ByteArrayInputStream bais = new ByteArrayInputStream(bytes
ps.setBinaryStream(1, bais, bytes.length)
Thank you for accepting :)
BTW I have some mistakes in my code, it should be:
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
out = new ObjectOutputStream(bos) ;
out.writeObject(<your multipart object here>);
out.close();
BTW I have some mistakes in my code, it should be:
ByteArrayOutputStream bos = new ByteArrayOutputStream() ;
out = new ObjectOutputStream(bos) ;
out.writeObject(<your multipart object here>);
out.close();
ASKER
You're welcome, I understood the idea... ;-)
http://www.developer.com/java/other/article.php/618471
Best Regards
Sudhakar