Reputation: 2725
I'm using the code below to send emails to users, it works as expected. The images show up within the html in the email. But noticed recently that there's an attachment icon that shows up also before clicking on the email. It's a minor issue, but slightly annoying. Having a hard time understanding why this is happening and how to stop it? Any ideas? Thanks.
public static void send(String useremail, String htmlBody,Map<String, String> mapInlineImages, String subject, String internetAddress, String websiteFrom) throws MalformedURLException{
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
String msgBody = "...";
try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(internetAddress, websiteFrom));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(useremail, "Admin"));
msg.setSubject(subject);
msg.setText(msgBody);
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(htmlBody, "text/html");
Multipart multipart = new MimeMultipart("related");
multipart.addBodyPart(messageBodyPart);
if (mapInlineImages != null && mapInlineImages.size() > 0) {
Set<String> setImageID = mapInlineImages.keySet();
for (String contentId : setImageID) {
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setHeader("Content-ID", "<" + contentId + ">");
imagePart.setDisposition(MimeBodyPart.INLINE);
String imageFilePath = mapInlineImages.get(contentId);
try {imagePart.attachFile(imageFilePath);
} catch (IOException ex) {ex.printStackTrace();
}multipart.addBodyPart(imagePart);}}
msg.setContent(multipart);
Transport.send(msg);
} catch (AddressException e) {}
catch (MessagingException e) {}
catch (UnsupportedEncodingException e) {}
}
Upvotes: 2
Views: 1661