Ignore chains and states default directories.
[rhynodge.git] / src / main / java / net / pterodactylus / reactor / actions / EmailAction.java
index 8f325aa..ef9d602 100644 (file)
@@ -24,9 +24,12 @@ 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;
+import net.pterodactylus.reactor.output.Output;
 
 /**
  * {@link Action} implementation that sends an email containing the triggering
@@ -69,16 +72,28 @@ public class EmailAction implements Action {
         * {@inheritDoc}
         */
        @Override
-       public void execute(Object trigger) {
+       public void execute(Output output) {
                Properties properties = System.getProperties();
                properties.put("mail.smtp.host", hostname);
                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. */