Sending JPEGs with "Aspirin"

24 views
Skip to first unread message

Isaac4given

unread,
Jul 19, 2005, 4:14:59 PM7/19/05
to wi...@googlegroups.com
Supposedly we need to create a MimeMultipart mimeMultipart object.

Then we need to call the addBodyPart method. We'll need to call it
twice to add the text message and the JPEG attachment.

Then use message.setContent(mimeMultipart).

After that we'll send the Message using Aspirin:

https://aspirin.dev.java.net/

How do we do this? Here's the JavaMail API doc:

http://java.cs.vt.edu/dev/javamail/javax/mail/Part.html

i...@users.sourceforge.net

unread,
Jul 27, 2005, 6:44:38 PM7/27/05
to wi...@googlegroups.com
One thing we're working on now, is to make a ready-to-send Java Mail
API email Message object containing a MimeMultipart content object for
a JPEG attachment (named "screen.jpg",) containing the JPEG image
data, not from a file, but from an AWT BufferedImage object.

I know how to save the BufferedImage object data to a JPEG file on the
hard disk, and how to load the data back out of the file into the email
message, but it makes the program much to slow to write a file on the
hard disk, and we need to figure out how to move the data directly from
the BufferedImage object into the email Message object without using
writing a file - if possible.

i...@users.sourceforge.net

unread,
Jul 28, 2005, 9:59:03 AM7/28/05
to wi...@googlegroups.com

Isaac4given

unread,
Aug 1, 2005, 11:08:05 AM8/1/05
to witl
I think you need to write your own DataSource or DataContentHandler for
BufferedImage.

If the Image object were serializable you could use this one:

(JavaMail and JAF)
MimeBodyPart mbp3=new MimeBodyPart();
mbp.setDataHandler(new DataHandler(new
ObjectDataSource(myAWTImage,"image/jpeg")));

maybe you know a way to make BufferedImager serializable.

(ImageIO)
static boolean write(RenderedImage im, String formatName, OutputStream
output)

Unless Images are serializable, I think that I would use the above
function to write the Image into a ByteArrayOutputStream.

Then you need to find or to write a DataSource Implementation which
uses the ByteArray as InputStream.

JavaMail is then able to create the email representation and with
Aspirin you can send it.

Have you checked out if other sourceforge projects could also be useful
for your project like this one:
http://jwma.sourceforge.net/index.html

regards

matjung

Mamiju

unread,
Aug 7, 2005, 5:56:28 PM8/7/05
to witl
I've created two files myOutputStream.java which extends
java.io.OutputStream and implements DataSource and Serializable.

with this Instrument you can safe an Image in the memory and deliver an
InputStream for the MimeBodyPart Object.

I tried to upload these files via CVS but the computer tells me that I
need write access for the repository.

I am using TortoiseCVS to communicate with the CVS repository.

it's not memory efficient, but it works.

Isaac4given

unread,
Aug 9, 2005, 12:24:27 PM8/9/05
to witl
totally awesome!

see the "Getting Started" discussion thread in this group for cvs
access information.

Isaac4given

unread,
Aug 12, 2005, 1:01:10 PM8/12/05
to witl
Aspirin Exception
~~~~~~~~~~~~~~~~~

We are receiving a runtime NullPointerException trying to send a text
email through Aspirin 0.6.6 running WitlApp.java :

D:\Java\mycvs\witl\com\isaac4\lgpl\witl>java
com.isaac4.lgpl.witl.WitlApp mye...@hotmail.com
04.08.2005 20:46:48 org.masukomi.aspirin.core.RemoteDelivery deliver
SCHWERWIEGEND: java.lang.NullPointerException
04.08.2005 20:46:48 org.masukomi.aspirin.core.RemoteDelivery deliver
WARNUNG: No mail server found for: hotmail.com
04.08.2005 20:46:48 org.masukomi.aspirin.core.RemoteDelivery
failMessage
WARNUNG: Permanent exception delivering mail
(javax.mail.inte...@1a0c10f-to-hotmail.com:
javax.mail.MessagingException: I found no MX record entries for the
hostname hotmail.com. I cannot determine where to send this message.
at
org.masukomi.aspirin.core.RemoteDelivery.deliver(RemoteDelivery.java:177)
at
org.masukomi.aspirin.core.RemoteDelivery.run(RemoteDelivery.java:486)
at
org.apache.commons.threadpool.DefaultThreadPool.run(DefaultThreadPool.java:156)
at java.lang.Thread.run(Unknown Source)

Of course using DummyMailer instead of DummyTextMailer or
AspirinJpegMailer , specified at the top LightWalker.java works fine-
it just saves a screenshot to the disk. So this doesn't work:

//private MailableImage mailer = new DummyMailer();
//private MailableImage mailer = new DummyTextMailer();
private MailableImage mailer = new AspirinJpegMailer();

And neither does this:

//private MailableImage mailer = new DummyMailer();
private MailableImage mailer = new DummyTextMailer();
//private MailableImage mailer = new AspirinJpegMailer();

But this will:

private MailableImage mailer = new DummyMailer();
//private MailableImage mailer = new DummyTextMailer();
//private MailableImage mailer = new AspirinJpegMailer();

Reply all
Reply to author
Forward
0 new messages