I´m trying to send alerts through jakarta mail, using a gmail account and for this I wanted to send a emoji on the subject.
Session session = Session.getInstance(properties, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(usr, pass);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
Address[] toUser = InternetAddress
.parse(toEmail);
message.setRecipients(Message.RecipientType.TO, toUser);
message.setSubject("\uD83D\uDEA8"+" This is an alert "+"\uD83D\uDEA8");
message.setContent(messageText, "text/html; charset=utf-8");
Transport.send(message);
}
I´ve tried every answer about this but I receive a ? every time I try to send it via tomcat server, using a psvm it is functional to use something like "\uD83D\uDEA8"+" This is an alert "+"\uD83D\uDEA8".
Don't upcast MimeMessage to Message. MimeMessage has a method
MimeMessage.setSubject(String subject, String charset)which takes the charset as an additional parameter.