I have this class:
public void sendMessage(String subject, String body, String mailTo, String pathToFile) throws MessagingException, IOException {
log.info("Sending email to: *{}* ", mailTo);
Session session = Session.getInstance(prop, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("info", "aT2coZt2UU");
}
});
//log.info("Sending email to1: " + mailTo);
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mailTo));
message.setSubject(subject);
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(body, "text/html; charset=utf-8");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
log.info("pathToFile: *{}* ", pathToFile);
if (pathToFile != null) {
MimeBodyPart attachment = new MimeBodyPart();
attachment.attachFile(pathToFile);
multipart.addBodyPart(attachment);
}
log.info("Setting content");
message.setContent(multipart);
log.info("Sending message {} ", message);
Transport.send(message);
}
I the String message I use:
+ "A equipe da Mystic River App. nn" +
" https://www.mystic-river.com";
But I receive the message without line breaks