发送电子邮件图像Bufferedimage/ImageIO
问题描述:
我想将base64图像转换为可以在gmail/outlook上看到的文件。目前,当我发送带有图像的电子邮件到我现有的Gmail时,图像消失,我可以看到除图像以外的所有文字。但我可以在我的苹果邮件中查看图像。我做了一些研究,它说gmail已经阻止了base64图像。所以我能做的唯一方法是转换base64图像。发送电子邮件图像Bufferedimage/ImageIO
<img alt=3D"" src=3D"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANsA=AABpCAIAAAA848FpAAAF/0lEQVR4nO2c2ZXjOAxFnW5l4VCcWyeADGo+elqmiIXgI......=3D" /></div>
我使用缓冲的image/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);
答
不,没有直接的方法。但是......
想象一下,图像的宽度和图像的高度HTML表和每个单元都有不同的背景颜色是这样的:
<td style=background:#ddde22 />
这是每一个约31字节像素。
如果您的64x64图像是64 * 64 * 31字节= 127kb的实色。
你可以住在一起吗?如果是这样,this discussion may help。