Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

set mime encoding for DataSource  RSS feed

 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to send HTML email with embedded images using CID:

It works fine with external files (.jpg, etc.) loaded with an instance of DataSource and DataHandler when the bytes come from a file on the disk drive.

I want to get the bytes from a database, so I have just a byte[]

The data is emailed, but the MIME-encoding is incorrect.

When read from a file, its set to
Content-Transfer-Encoding: base64
This works perfectly.

When I set the bytes from an array in memory, the
headers look like:
Content-Type: image/jpeg; name=alert.jpg
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename=alert.jpg
Content-ID: <cidtest>

with the incorrect encoding.
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javax.mail.util.ByteArrayDataSource is a DataSource backed by a byte array. The byte array may declared in the constructor directly.

ref: Class ByteArrayDataSource
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, the solution is to have raw data, use it as the source, and let the API do the encoding to MIME
 
Nicholas Jordan
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's how I read the javadocs, and boldly went with that answer but as usual, all caveats apply.

(Except as noted in the caveat correction manual.)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!