【问题标题】:Send email image Bufferedimage/ImageIO发送电子邮件图像 Bufferedimage/ImageIO
【发布时间】: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


    【解决方案1】:

    不,没有直接的方法。但是……

    想象一个 html-table 具有图像的宽度和图像的高度,并且每个单元格都有不同的背景颜色,如下所示:

    <td style=background:#ddde22 />
    

    每个像素大约有 31 个字节。

    如果您有一个 64x64 的图像,它的 64*64*31 字节 = 127kb(真彩色)。

    你能忍受吗?

    如果是,this discussion may help

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-20
      • 2015-08-01
      • 2013-06-01
      • 2012-04-24
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 2013-04-20
      相关资源
      最近更新 更多