Connect the SMTP transport before sending a mail.
[rhynodge.git] / src / main / java / net / pterodactylus / rhynodge / actions / EmailAction.java
index 5c57822..0a0aca7 100644 (file)
@@ -35,6 +35,7 @@ import javax.mail.internet.MimeMultipart;
 import net.pterodactylus.rhynodge.Action;
 import net.pterodactylus.rhynodge.output.Output;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.sun.mail.smtp.SMTPTransport;
 
 /**
@@ -73,6 +74,14 @@ public class EmailAction implements Action {
                transport = new SMTPTransport(session, new URLName("smtp", hostname, 25, null, "", ""));
        }
 
+       @VisibleForTesting
+       EmailAction(Transport transport, String sender, String recipient) {
+               this.transport = transport;
+               this.sender = sender;
+               this.recipient = recipient;
+               this.session = getInstance(getProperties());
+       }
+
        //
        // ACTION METHODS
        //
@@ -100,6 +109,7 @@ public class EmailAction implements Action {
                        multipart.addBodyPart(htmlPart);
                        message.setContent(multipart);
 
+                       transport.connect();
                        transport.sendMessage(message, message.getAllRecipients());
                } catch (MessagingException me1) {
                        /* swallow. */