Uploaded image for project: 'Commons Email'
  1. Commons Email
  2. EMAIL-26

[email] Bad Exception message when using a supplied MailSession

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • None
    • None
    • Operating System: Windows XP
      Platform: PC

    • 38538

    Description

      I create a MultiPartEmail object and supply a javax.mail.Session as a param to
      the setMailSession() method. I do not explicitly set the hostname or port.
      After stting the rest of the desired/required fields, I call send().

      I happened to have a javax.mail.MessagingException get thrown which was caught
      in Email, specifically, sendMimeMessage(). What I noticed was that the
      stacktrace in my log read the following:

      org.apache.commons.mail.EmailException: Sending the email to the following
      server failed : null:25
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:873)
      at org.apache.commons.mail.Email.send(Email.java:898)
      at com.csc.aims.util.jobs.SendMailJob.sendEmail(SendMailJob.java:219)
      at com.csc.aims.util.jobs.SendMailJob.execute(SendMailJob.java:186)
      at org.quartz.core.JobRunShell.run(JobRunShell.java:195)
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run
      (SimpleThreadPool.java:520)
      Caused by: javax.mail.MessagingException: Could not connect to SMTP host:
      smtp.server.address, port: 25;
      nested exception is:
      java.net.ConnectException: Connection refused: connect
      at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1213)
      at com.sun.mail.smtp.SMTPTransport.protocolConnect
      (SMTPTransport.java:311)
      at javax.mail.Service.connect(Service.java:233)
      at javax.mail.Service.connect(Service.java:134)
      at javax.mail.Service.connect(Service.java:86)
      at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:144)
      at javax.mail.Transport.send0(Transport.java:150)
      at javax.mail.Transport.send(Transport.java:80)
      at org.apache.commons.mail.Email.sendMimeMessage(Email.java:863)
      ... 5 more

      As can be seen, the MessagingException knows the hostname (hostname changed to
      protect the innocent , yet the EmailException does not. After taking a
      closer look, the str that is generated for the Exception message uses the
      hostname property, yet upon tracing the code, the hostname never gets set by
      this code execution path.

      My expectation was that since I supplied a valid Session object (with
      hostname) that the Email class would be able to extract that info back out of
      it.

      Attachments

        Activity

          People

            Unassigned Unassigned
            cdeal@csc.com Charles Deal
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: