Prevent gmail from showing inline images as attachments

I am using the spring samples to send inline images. It works but gmail shows images also as attachments. How to avoid it?

enter image description here

The code is pretty simple.

public class Email {

    public static  MimeMessagePreparator getContentAsInlineResourceMessagePreparator(final String to) {

        MimeMessagePreparator preparator = new MimeMessagePreparator() {

            public void prepare(MimeMessage mimeMessage) throws Exception {
                MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "UTF-8");

                helper.setSubject("Email with inline image");
                helper.setFrom("fake@yourshop.com");
                helper.setTo(to);

                String content = "Dear pedrofb...";
                helper.setText("<html><body><p>" + content + "</p><img src='cid:company-logo'></body></html>", true);
                helper.addInline("company-logo", new ClassPathResource("logo.png"));
            }
        };
        return preparator;
    }
    public final static void main (String argv[]){
        //Omitted SMTP configuration
        JavaMailSenderImpl mailSender = SmtpServer.toJavaMailSender(smtpServer);

        MimeMessagePreparator preparator = getContentAsInlineResourceMessagePreparator("myemail@gmail.com");            
        mailSender.send(preparator);
    }

}

My question is similar to How to stop embedded images in email being displayed as attachments by GMail? but the answer is very old and it does not show how to configure spring properly. I do not want to build the message parts&headers myself


Posted the raw message in pastebin

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s