I am trying to convert base64 image to a file that can be seen on gmail/outlook. Currently when I send an email with an image to my existing gmail, the image disappears, I can see all the text except for the image. But I can view the image in my apple mail. I have done some researching, it says that gmail has blocked base64 images. So the only way I can do is to convert base64 images.
<img alt=3D"" src=3D"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsA=AABpCAIAAAA848FpAAAF/0lEQVR4nO2c2ZXjOAxFnW5l4VCcWyeADGo+elqmiIXgI......=3D" /></div>
I modified my codes using buffered image/imageIO but it doesnt make a difference when I send the email. Is there anything wrong with this? Or is there any other ways to allow base64 images to be seen?
This is my codes for the image.
String _message = _n.getRichcontent();
String[] _s = _message.split(",");
String message = _s[1];
System.out.println(_s[1]);
// create a buffered image
BufferedImage image = null;
byte[] imageByte;
BASE64Decoder decoder = new BASE64Decoder();
try {
imageByte = decoder.decodeBuffer(message);
ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
image = ImageIO.read(bis);
System.out.println("Reading complete.");
bis.close();
// write the image to a file
File outputfile = new File("image.png");
ImageIO.write(image, "png", outputfile);
System.out.println("Writing complete." + outputfile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Error: "+e);
}
This is the code for the image to appear in my email.
_msg = _msg + _message + "<BR><BR>";
This is to send the email.
sendMail(_sender, _receipients, _subject, _msg);