• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Image to String to Image in a email

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#IncludingImagesWithHTML

edit http://java.sun.com/developer/onlineTraining/JavaMail/exercises/MailHtml/solution/HtmlImageExample.java
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic