Implement sending the mail as multipart/alternative.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 3 Jan 2013 15:35:58 +0000 (16:35 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Thu, 3 Jan 2013 15:35:58 +0000 (16:35 +0100)
src/main/java/net/pterodactylus/reactor/actions/EmailAction.java

index 8f325aa..64673e4 100644 (file)
@@ -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. */