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.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);
|
||||
|
|
|
@ -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,11 +51,18 @@ public class EmailServiceLiveTest {
|
|||
.toString();
|
||||
}
|
||||
|
||||
private static String attachmentContentsFrom(MimeMessage receivedMessage) throws Exception {
|
||||
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(2)
|
||||
.getContent()
|
||||
.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue