X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Factions%2FEmailAction.java;h=e1441f3b07e18ad1479da081fde6ba90cd6f93be;hb=HEAD;hp=b781f4dd1af2e377ceca453654c7ced35afaa27a;hpb=9a680a53a499cf29a66c05154f83c415acc3ba8f;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java b/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java index b781f4d..e1441f3 100644 --- a/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java +++ b/src/main/java/net/pterodactylus/rhynodge/actions/EmailAction.java @@ -37,6 +37,7 @@ import net.pterodactylus.rhynodge.output.Output; import com.google.common.annotations.VisibleForTesting; import com.sun.mail.smtp.SMTPTransport; +import org.apache.log4j.Logger; /** * {@link Action} implementation that sends an email containing the triggering @@ -46,6 +47,8 @@ import com.sun.mail.smtp.SMTPTransport; */ public class EmailAction implements Action { + private static final Logger logger = Logger.getLogger(EmailAction.class); + /** The email address of the sender. */ private final String sender; @@ -105,28 +108,30 @@ public class EmailAction implements Action { addHtmlPart(output, multipart); message.setContent(multipart); - transport.connect(); + if (!transport.isConnected()) { + transport.connect(); + } transport.sendMessage(message, message.getAllRecipients()); } catch (MessagingException me1) { - /* swallow. */ + logger.error("Could not send email!", me1); } } private void addPlainTextPart(Output output, MimeMultipart multipart) throws MessagingException { - if (output.text("text/plain", -1) == null) { + if (output.text("text/plain") == null) { return; } MimeBodyPart textPart = new MimeBodyPart(); - textPart.setContent(output.text("text/plain", -1), "text/plain;charset=utf-8"); + textPart.setContent(output.text("text/plain"), "text/plain;charset=utf-8"); multipart.addBodyPart(textPart); } private void addHtmlPart(Output output, MimeMultipart multipart) throws MessagingException { - if (output.text("text/html", -1) == null) { + if (output.text("text/html") == null) { return; } MimeBodyPart htmlPart = new MimeBodyPart(); - htmlPart.setContent(output.text("text/html", -1), "text/html;charset=utf-8"); + htmlPart.setContent(output.text("text/html"), "text/html;charset=utf-8"); multipart.addBodyPart(htmlPart); }