I am sending HTML emails with embedded images by using the following code:
HtmlEmail email = new HtmlEmail();
email.setCharset("utf-8");
String html=....;
String txt=....;
Map map=new HashMap();
map.put("charset",CHARSET);
map.put("List-Unsubscribe","<mailto:abc@example.com>, <https://example.com/");
map.put("X-property", property);
email.setHeaders(map);
email.setHostName(HOSTNAME);
email.setSmtpPort(PORT);
email.setFrom(from, fromname);
email.setBounceAddress(frombounce);
email.setSubject(subject);
Iterator<String> it=inlineImages.iterator();
URL url=null;
String cid = "";
String imgurl ="";
while (it.hasNext())
{
imgurl=it.next();
url = (getPathFromLocalFile(imgurl));
cid = email.embed(url, getName(imgurl));
html=StringTools.replace(html,imgurl,"cid:"+cid);
}
email.addTo(to);
email.setTextMsg(textbody);
email.setHtmlMsg(htmlbody);
email.setHostName(HOSTNAME);
.....
email.setSubject(subject);
email.send();
The code works fine, as I receive a nice Email in the end. The images are embedded and in Thunderbird, the user immediately sees the correct html with images. However, there are some clients that don't work properly. Those are Outlook, K9-Mail for Android or Roundcube. Here, I see the paperclip symbol for attachements. Nevertheless, the mail looks great, so no need to press a button to download them. Probably something is wrong with the Content-Type of the mail, but I am not sure about this.
Can anyone see whats wrong?
EDIT: Heres the header as plain text.
Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on test@example.com X-Spam-Level: X-Spam-Status: No, score=-1.9 required=4.0 tests=BAYES_00,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_MSPIKE_H2,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 X-Original-To: test@example.com Delivered-To: test@example.com Received: from mout.example.net (mout.example.net [77.77.77.77]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.example.eu (Postfix) with ESMTPS id 7275A7AB8687 for ; Fri, 10 Jun 2016 15:41:56 +0200 (CEST) Received: from example ([77.77.77.77]) by mail.example.com (mrexample001) with ESMTPSA (Nemesis) id 0Lw2Sj-1bWOaM07n3-017j0o for ; Fri, 10 Jun 2016 15:41:55 +0200 Date: Fri, 10 Jun 2016 15:41:47 +0200 (CEST) From: Testaccount von example To: test@example.com Message-ID: <809223752.3.1465566107118.JavaMail.user@example> Subject: =?UTF-8?Q?Sch=C3=BCtzen_Sie_sich_mit_unanfec?= =?UTF-8?Q?= MIME-Version: 1.0 Content-Type: multipart/mixed;
boundary="----=_Part_0_1010418160.1465566107019" charset: utf-8 X-Customer: 12u890812792 List-Unsubscribe: , https://example.com/method=unsubscribe&email=12u890812792&unsubscribe=true X-Provags-ID: V03:K0:+WezTQKC0rV+i+/Dkvjm1Zp0+w6o6ZGZNXBvIMdU0ANaUTEIxow 63iaYyDyxW74ZNkXdFRiDea9DyQdordqCoprE2tJEhtDIS+ceHt+Q9eb+tSCyf1ADE6bZja NDJKYXWJdW0NeAZydDcVP/8Er5knlmumhlyEhlnjFGmqbiBuO4wP3KqqC3vkh5rYFVaZe9V pM8Mox3lSMx4V/gh7Tp0g== X-UI-Out-Filterresults: notjunk:1;V01:K0:twqiq4jOtPg=:bALN2jRhEVBD8MkqJgqyHi FerpGKfqCgKcqiw2MdjebvuPKTI12CaGUIBMBiionmrMEmEXNENQNV/xK6b+8QAYHLixWQqZc TC9lJFf8r2OcEpyNnFlNTHm8c/b/GbbOR/TUfk9W487HaXattRdnfsiZH/eFRiPcGB9y4gtZY G03G7U0rFPTcIvvHG10Ubc5eWq7v+Ptm6G9emlihE0Axc0flWW8K/j8Xat1l5KZ2OksQFrSAH YJlOEmoQM87W56bpqmZ+3T8/qUVDpdrV5KTdf0Y6wekk4lB3Po421sddZALqvWWZbWPBHS5Ce gFyTSfT55Gc38mDtoEABkWWJC7n15yci/MXkcHzvyHswMli3pGu6Gv5YteG6w0aVHP2FTtNgJ nn/6aWdDITy8SVr03WdWKN+aNERwt79aTVorOE5RBqDuYk7DN8i190nNEEfgL1dRjF+Zx+31o Xvh6rYSN1anm7CxVC06VbstGLY6Rrq0Ore+5s+Obv+X20FL/ao2LwqtJ96EiRcKsO1H+T5t1F HEEscuUO0yASaWDxXVb+uoYy06IwgITc0TwuLZ1qGUxtIIIy4CIvZEw68CbAih3BFstV8zRid DLFrdHtf+hBfon1P4uRp5kkyB+47w7G1Or3bPISqp/zhdq7LsYbFP5AuwXzGcQdP7IPAbeIGp oGUCTm74nqITGbfW/jqV27c1viJn3GEGHt90HmyYNJHqGS/dW2wiaeQhgIV+Wp/Pm7cb/GwgB qAx54/FxoLO4nR5wvLqcUNlsO1t7xepEBl5puvmWyLZR++AsnEhcK/6ZqdQ= X-Virus-Status: No X-Virus-Checker-Version: clamassassin 1.2.4 with clamdscan / ClamAV 0.98.7/21704/Fri Jun 10 11:44:45 2016 X-Spambayes-Classification: ham; 0.03 X-Virustotal-Status: No X-Virustotal-String: # not checked:none/text/plain# not checked:none/text/html# not checked:1465566109864.png/image/png# not checked:1465566121103.png/image/png# not checked:1465566117059.png/image/png# not checked:1465566110651.png/image/png# not checked:1465566109052.png/image/png# not checked:1465566113630.png/image/png# not checked:1465566121054.png/image/png# not checked:1465566115535.png/image/png# not checked:1465566109346.png/image/png# not checked:1465566114750.png/image/png# not checked:1465566108289.png/image/png# not checked:1465566113027.png/image/png# not checked:1465566115345.png/image/png# not checked:1465566117438.png/image/png# not checked:1465566119754.png/image/png