From 4e77e4c70dd1307ca6e7b63e2f42426bc50be707 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 3 Jan 2013 16:35:58 +0100 Subject: [PATCH] Implement sending the mail as multipart/alternative. --- .../net/pterodactylus/reactor/actions/EmailAction.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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. */ -- 2.7.4