This week's book giveaway is in the Web Services forum.
We're giving away four copies of Microservices in Action and have Morgan Bruce & Paulo A. Pereira on-line!
See this thread for details.
Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Image to String to Image in a email  RSS feed

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The query seems complicated to me because of some constraints.
Constraints:
Have to use String message which should contain image. Not aware how can I convert a gif/jpeg/bmp/png image to java string object.
This string message object will be passed to one of my framework methods send(String type, String subject, String message) to send an email. In my email I want that image to come properly and shown to the user. there is no option to pass the image. It needs to be passed as String message.
Internally the send method of the framework will create MimeMessage etc. and send email.
Type of the email will be text/html.

What could be the best possible solution to send a image as a message body when the method send takes only String argument?

Thanks
 
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I assume that behind the scenes you are using the JavaMail API to send the email. In which case you need to add a method to your framework that allows you to send a MimeMultipart attachment. There are examples of how to do this in the JavaMail distribution.

Note - JavaMail Base64 encodes binary data which means it only contains ASCII characters.
 
Gaurav Kr. Arora
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

James Sabre wrote:I assume that behind the scenes you are using the JavaMail API to send the email. In which case you need to add a method to your framework that allows you to send a MimeMultipart attachment. There are examples of how to do this in the JavaMail distribution.

Note - JavaMail Base64 encodes binary data which means it only contains ASCII characters.



I don't want to send the image as an attachment. Instead I want to send it as a message body. How can we achieve this?
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gaurav Kr. Arora wrote:

I don't want to send the image as an attachment. Instead I want to send it as a message body. How can we achieve this?



It is easy enough to Base64 encode the image and add that as the body part BUT it will not then have the correct mime type and without research I don't know how to make it have the correct mime type. Sorry I can't help.

Bye
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!