BAEL-4569: Formatting Email Text (#11910)

This commit is contained in:
ACHRAF TAITAI 2022-03-08 21:52:10 +01:00 committed by GitHub
parent c1751dc317
commit c1d1134fb3
2 changed files with 14 additions and 1 deletions

View File

@ -67,12 +67,17 @@ public class EmailService {
MimeBodyPart mimeBodyPart = new MimeBodyPart();
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();
attachmentBodyPart.attachFile(getFile());
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
multipart.addBodyPart(mimeBodyPartWithStyledText);
multipart.addBodyPart(attachmentBodyPart);
message.setContent(multipart);

View File

@ -36,6 +36,7 @@ public class EmailServiceLiveTest {
MimeMessage receivedMessage = receivedMessages[0];
assertEquals("Mail Subject", subjectFromMessage(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));
}
@ -50,9 +51,16 @@ public class EmailServiceLiveTest {
.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 {
return ((MimeMultipart) receivedMessage.getContent())
.getBodyPart(1)
.getBodyPart(2)
.getContent()
.toString();
}