BAEL-4569: Formatting Email Text (#11910)
This commit is contained in:
parent
c1751dc317
commit
c1d1134fb3
|
@ -67,12 +67,17 @@ public class EmailService {
|
||||||
MimeBodyPart mimeBodyPart = new MimeBodyPart();
|
MimeBodyPart mimeBodyPart = new MimeBodyPart();
|
||||||
mimeBodyPart.setContent(msg, "text/html; charset=utf-8");
|
mimeBodyPart.setContent(msg, "text/html; charset=utf-8");
|
||||||
|
|
||||||
|
String msgStyled = "This is my <b style='color:red;'>bold-red email</b> using JavaMailer";
|
||||||
|
MimeBodyPart mimeBodyPartWithStyledText = new MimeBodyPart();
|
||||||
|
mimeBodyPartWithStyledText.setContent(msgStyled, "text/html; charset=utf-8");
|
||||||
|
|
||||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||||
|
|
||||||
attachmentBodyPart.attachFile(getFile());
|
attachmentBodyPart.attachFile(getFile());
|
||||||
|
|
||||||
Multipart multipart = new MimeMultipart();
|
Multipart multipart = new MimeMultipart();
|
||||||
multipart.addBodyPart(mimeBodyPart);
|
multipart.addBodyPart(mimeBodyPart);
|
||||||
|
multipart.addBodyPart(mimeBodyPartWithStyledText);
|
||||||
multipart.addBodyPart(attachmentBodyPart);
|
multipart.addBodyPart(attachmentBodyPart);
|
||||||
|
|
||||||
message.setContent(multipart);
|
message.setContent(multipart);
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class EmailServiceLiveTest {
|
||||||
MimeMessage receivedMessage = receivedMessages[0];
|
MimeMessage receivedMessage = receivedMessages[0];
|
||||||
assertEquals("Mail Subject", subjectFromMessage(receivedMessage));
|
assertEquals("Mail Subject", subjectFromMessage(receivedMessage));
|
||||||
assertEquals("This is my first email using JavaMailer", emailTextFrom(receivedMessage));
|
assertEquals("This is my first email using JavaMailer", emailTextFrom(receivedMessage));
|
||||||
|
assertEquals("This is my <b style='color:red;'>bold-red email</b> using JavaMailer", emailStyledTextFrom(receivedMessage));
|
||||||
assertEquals("sample attachment content", attachmentContentsFrom(receivedMessage));
|
assertEquals("sample attachment content", attachmentContentsFrom(receivedMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,9 +51,16 @@ public class EmailServiceLiveTest {
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String emailStyledTextFrom(MimeMessage receivedMessage) throws IOException, MessagingException {
|
||||||
|
return ((MimeMultipart) receivedMessage.getContent())
|
||||||
|
.getBodyPart(1)
|
||||||
|
.getContent()
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
private static String attachmentContentsFrom(MimeMessage receivedMessage) throws Exception {
|
private static String attachmentContentsFrom(MimeMessage receivedMessage) throws Exception {
|
||||||
return ((MimeMultipart) receivedMessage.getContent())
|
return ((MimeMultipart) receivedMessage.getContent())
|
||||||
.getBodyPart(1)
|
.getBodyPart(2)
|
||||||
.getContent()
|
.getContent()
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue