【发布时间】:2016-11-29 12:29:21
【问题描述】:
我正在尝试将 base64 图像转换为可以在 gmail/outlook 上看到的文件。目前,当我向现有的 gmail 发送带有图像的电子邮件时,图像消失了,我可以看到除图像之外的所有文本。但我可以在我的苹果邮件中查看图像。我做了一些研究,它说 gmail 已经阻止了 base64 图像。所以我唯一能做的就是转换base64图像。
<img alt=3D"" src=3D"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsA=AABpCAIAAAA848FpAAAF/0lEQVR4nO2c2ZXjOAxFnW5l4VCcWyeADGo+elqmiIXgI......=3D" /></div>
我使用缓冲图像/imageIO 修改了我的代码,但在我发送电子邮件时并没有什么不同。这有什么问题吗?或者有没有其他方法可以让 base64 图像被看到?
这是我的图片代码。
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);
}
这是显示在我的电子邮件中的图像的代码。
_msg = _msg + _message + "<BR><BR>";
这是发送电子邮件。
sendMail(_sender, _receipients, _subject, _msg);
【问题讨论】:
标签: java email base64 bufferedimage javax.imageio