From: David ‘Bombe’ Roden Date: Thu, 3 Jan 2013 15:35:58 +0000 (+0100) Subject: Implement sending the mail as multipart/alternative. X-Git-Tag: 0.1~90 X-Git-Url: https://git.pterodactylus.net/?p=rhynodge.git;a=commitdiff_plain;h=4e77e4c70dd1307ca6e7b63e2f42426bc50be707 Implement sending the mail as multipart/alternative. --- diff --git a/src/main/java/net/pterodactylus/reactor/actions/EmailAction.java b/src/main/java/net/pterodactylus/reactor/actions/EmailAction.java index 8f325aa..64673e4 100644 --- a/src/main/java/net/pterodactylus/reactor/actions/EmailAction.java +++ b/src/main/java/net/pterodactylus/reactor/actions/EmailAction.java @@ -24,7 +24,9 @@ import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMultipart; import net.pterodactylus.reactor.Action; @@ -75,10 +77,22 @@ public class EmailAction implements Action { Session session = Session.getInstance(properties); MimeMessage message = new MimeMessage(session); try { + /* create message. */ message.setFrom(new InternetAddress(sender)); message.setRecipient(RecipientType.TO, new InternetAddress(recipient)); - message.setSubject("Reaction Triggered!"); - message.setText(String.valueOf(trigger)); + message.setSubject(output.summary()); + + /* create text and html parts. */ + MimeMultipart multipart = new MimeMultipart(); + multipart.setSubType("alternative"); + MimeBodyPart textPart = new MimeBodyPart(); + textPart.setContent(output.text("text/plain", -1), "text/plain;charset=utf-8"); + MimeBodyPart htmlPart = new MimeBodyPart(); + htmlPart.setContent(output.text("text/html", -1), "text/html;charset=utf-8"); + multipart.addBodyPart(textPart); + multipart.addBodyPart(htmlPart); + message.setContent(multipart); + Transport.send(message); } catch (MessagingException me1) { /* swallow. */