https://issues.apache.org/bugzilla/show_bug.cgi?id=46063

           Summary: MailLogger does not work correctly with SSL
           Product: Ant
           Version: 1.7.1
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: major
          Priority: P3
         Component: Optional Tasks
        AssignedTo: notifications@ant.apache.org
        ReportedBy: [EMAIL PROTECTED]


MailLogger cannot connect properly to a mail server that requires the use of
TLS/SSL. It also fails to enable the STARTTLS command, which would allow the
mail server to ask the client to switch to SSL.

As a result of this, it isn't possible to use MailLogger with Gmail, and I'm
sure this bug would also affect a number of other popular email services.

To replicate the problem:

    MailLogger.mailhost=smtp.gmail.com
    MailLogger.mailport=465
    MailLogger.ssl=true
    MailLogger.user=<sender account>
    MailLogger.password=<sender password>
    MailLogger.from=<sender email>
    MailLogger.success.to=<recipient email>
    MailLogger.failure.to=<recipient email>

Please note that bug 44009 will cause a NullPointerException when you specify a
username and password, so it will be necessary to correct this first.

I think it's possible that SSL support, which must have worked at one time, has
been broken by some change in JavaMail. I'm using JavaMail 1.4.1 (which is the
most recent release), and JavaBeans Activation Framework 1.1.1 (also the most
recent release).

I was able to fix the problem by modifying the send() method of MimeMailer.
Near the end of this method, you'll find the following line:

    Transport.send(msg);

This method doesn't seem to work with SSL. That may well be a bug in JavaMail,
but it's easy to work around it by substituting the following code:

    // Send the message using SMTP, or SMTPS if the host uses SSL
    Transport transport = sesh.getTransport(SSL ? "smtps" : "smtp");
    transport.connect(host, user, password);
    transport.sendMessage(msg, msg.getAllRecipients());

While I was working on MimeMailer, I also added the following just before the
code that initializes sesh with a new JavaMail session:

    // Enable STARTTLS to allow the host to initiate a switch to SSL
    props.put("mail.smtp.starttls.enable", "true");

Enabling STARTTLS would make it possible for MailLogger to work with a mail
server that will accept an unencrypted connection, but requires a client to
switch over to SSL once the connection has been established.

Gmail does this. It sends a STARTTLS command if you connect to it using the
standard SMTP port 25. So you should be able to test this using the following
settings:

    MailLogger.mailhost=smtp.gmail.com
    MailLogger.mailport=25
    MailLogger.ssl=false
    MailLogger.user=<sender account>
    MailLogger.password=<sender password>
    MailLogger.from=<sender email>
    MailLogger.success.to=<recipient email>
    MailLogger.failure.to=<recipient email>

It's possible that you might also want to add a new MailLogger configuration
property to enable/disable the use of STARTTLS, but IMHO it should be enabled
by default. That would help keep people from running into SSL-related problems.


-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Reply via email to