简体   繁体   English

在GAE中发送带有图片的HTML电子邮件

[英]Sending an html email with an image in GAE

When I send an e-mail currently from within GAE I receive the email with a Content-Transfer-Encoding of quoted-printable. 当我当前从GAE内部发送电子邮件时,我收到的电子邮件带有Content-Transfer-Encoding为quoted-printable的内容。 I am looking to set this to base64. 我希望将其设置为base64。 The quoted-printable would be find except the image is not displayed when I receive the email. 我收到电子邮件后会找到带引号的可打印内容,但不显示图像。 As it is right now my html which looks like this: 现在是我的html,它看起来像这样:

String base64StringImg = Base64.encode(my byte array);

StringBuilder htmlBody = new StringBuilder();
htmlBody.append("<html>");
htmlBody.append("<body>");
htmlBody.append("<img src='data:image/png;base64,");
htmlBody.append(base64StringImg);
htmlBody.append("'/>");
htmlBody.append("<br/><br/>");
htmlBody.append("Hello " + name); 
htmlBody.append("</body>");
htmlBody.append("</html>");


MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromUser));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(recipient));
message.setSubject(subject);
Multipart mp = new MimeMultipart();

BodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(htmlBody.toString(), "text/html; charset=UTF-8");
mp.addBodyPart(htmlPart);
message.setContent(mp);
Transport.send(message);

How can I send an html e-mail with an image in GAE? 如何在GAE中发送带有图像的html电子邮件? I have read the following two bug/feature requests which make it clear there are limitations. 我已经阅读了以下两个bug /功能请求,这些请求清楚说明了局限性。

http://code.google.com/p/googleappengine/issues/detail?id=198 http://code.google.com/p/googleappengine/issues/detail?id=965 http://code.google.com/p/googleappengine/issues/detail?id=198 http://code.google.com/p/googleappengine/issues/detail?id=965

HTML embedded images seem to be poorly supported in email clients: http://www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/ 电子邮件客户端中似乎不太支持HTML嵌入式图像: http//www.campaignmonitor.com/blog/post/1761/embedding-images-in-email/

What is supported are images HTML images attached to email: http://www.campaignmonitor.com/blog/post/1759/embedding-images-revisited/ 支持的是附在电子邮件上的图像HTML图像: http : //www.campaignmonitor.com/blog/post/1759/embedding-images-revisited/

However, as you noted with the link to the issue , the second option is poorly supported in GAE. 但是,正如您在指向问题的链接中所指出的那样,GAE对第二个选项的支持很差。 What you could try is create by hand the mail content shown in second link. 您可以尝试手动创建第二个链接中显示的邮件内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM