I am sending multi part email which is having text/plain and text/html but when i am getting mail in my outlook html content is coming as attachment and text/plain is coming in the body. i want both in the body.
pom.xml configuration is this
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.2</version>
</dependency>
and java code is
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put("mail.smtp.host", sSMTPServer);
props.put("mail.smtp.port", 25);
Session session = null;
session = Session.getInstance(props, null);
MimeMessage msg = new MimeMessage(session);
Multipart mainMultipart = new MimeMultipart("mixed");
Multipart htmlAndTextMultipart = new MimeMultipart("alternative");
MimeBodyPart BodyPart = new MimeBodyPart();
BodyPart.setText(Header);
htmlAndTextMultipart.addBodyPart(BodyPart);
MimeBodyPart BodyPart1 = new MimeBodyPart();
BodyPart1.setContent(Body, "text/html; charset=utf-8");
htmlAndTextMultipart.addBodyPart(BodyPart1);
for (int i = 0; i < htmlAndTextMultipart.getCount(); i++) {
mainMultipart.addBodyPart(htmlAndTextMultipart.getBodyPart(i));
}
msg.setContent(mainMultipart);
InternetAddress[] from = InternetAddress.parse("[email protected]");
InternetAddress[] toList = InternetAddress.parse(to);
msg.addFrom(from);
msg.addRecipients(Message.RecipientType.TO, toList);
msg.setSubject("Multipart_Testing");
Transport transport = session.getTransport("smtp");
transport.connect(sSMTPServer, 25, null,
null);
transport.sendMessage(msg, toList);
System.out.println("Sent");
transport.close();
}
problem is only with outlook that html content is not coming in the body
and in outlook all contents are not getting rendered like gmail instead coming as attachment
mail snippet of outlook