Mailapi.jar not working correctly

Post here questions and problems related to oXygen frameworks/document types.
DirkDubois
Posts: 22

Mailapi.jar not working correctly

Fri Jun 12, 2015 9:42 pm

Hello,

I have a custom Author Action implemented in a AuthorOperation Java class. I need it to send an email. I wrote the following class to send an email

Code: Select all

public class SendEmail {
   public static void send(String data){
      // Recipient's email ID needs to be mentioned.
         String to = "ddubois1@matrox.com";

         // Sender's email ID needs to be mentioned
         String from = "techwriting@matrox.com";

         // Assuming you are sending email from localhost
         String host = "mailbox.matrox.com";

         // Get system properties
         Properties properties = System.getProperties();

         // Setup mail server
         properties.put("mail.smtp.host", host);

         // Get the default Session object.
         Session session = Session.getInstance(properties, null);

         try{
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);

            // Set From: header field of the header.
            message.setFrom(new InternetAddress(from));

            // Set To: header field of the header.
            message.addRecipient(Message.RecipientType.TO,
                                     new InternetAddress(to));

            // Set Subject: header field
            message.setSubject("This is the Subject Line!");

            // Now set the actual message
            message.setText(data);

            // Send message
            Transport.send(message);
            
         }catch (MessagingException mex) {
            mex.printStackTrace();
         }
   }
}


However, when I debug my code from Eclipse in oxygen, once I reach the Transport.send() function, I always get this error:

Code: Select all

javax.mail.NoSuchProviderException: smtp
   at javax.mail.Session.getService(Session.java:775)
   at javax.mail.Session.getTransport(Session.java:713)
   at javax.mail.Session.getTransport(Session.java:656)
   at javax.mail.Session.getTransport(Session.java:636)
   at javax.mail.Session.getTransport(Session.java:691)
   at javax.mail.Transport.send0(Transport.java:188)
   at javax.mail.Transport.send(Transport.java:120)
   at com.matrox.mil.SendEmail.send(SendEmail.java:45)
   at com.matrox.mil.VisualSourceSafe.checkInFile(VisualSourceSafe.java:71)
   at com.matrox.mil.CheckInVSS.doOperation(CheckInVSS.java:28)
   at ro.sync.ecss.extensions.h.k(Unknown Source)
   at ro.sync.ecss.extensions.h.performAction(Unknown Source)
   at ro.sync.ecss.extensions.k.gzc(Unknown Source)
   at ro.sync.ui.application.d.m.actionPerformed(Unknown Source)
   at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
   at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
   at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
   at javax.swing.AbstractButton.doClick(Unknown Source)
   at com.jidesoft.plaf.vsnet.VsnetMenuItemUI.doClick(Unknown Source)
   at com.jidesoft.plaf.vsnet.VsnetMenuItemUI$MouseInputHandler.mouseReleased(Unknown Source)
   at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
   at java.awt.Component.processMouseEvent(Unknown Source)
   at javax.swing.JComponent.processMouseEvent(Unknown Source)
   at java.awt.Component.processEvent(Unknown Source)
   at java.awt.Container.processEvent(Unknown Source)
   at java.awt.Component.dispatchEventImpl(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
   at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
   at java.awt.Container.dispatchEventImpl(Unknown Source)
   at java.awt.Window.dispatchEventImpl(Unknown Source)
   at java.awt.Component.dispatchEvent(Unknown Source)
   at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
   at java.awt.EventQueue.access$200(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.awt.EventQueue$3.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
   at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue$4.run(Unknown Source)
   at java.awt.EventQueue$4.run(Unknown Source)
   at java.security.AccessController.doPrivileged(Native Method)
   at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
   at java.awt.EventQueue.dispatchEvent(Unknown Source)
   at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
   at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
   at java.awt.EventDispatchThread.run(Unknown Source)


I understand that this class needs to be apart of my class path etc, but seeing as it is a library loaded by oxygen, I would assume there is no extra work for me to do. In my C# code I use the same mailbox to send SMTP email with no user name or authorization. Any help would be greatly appreciated.

Thanks,
Dirk
XML Programmer, Technical Writing
Matrox Imaging
Radu
Posts: 5757

Re: Mailapi.jar not working correctly

Mon Jun 15, 2015 9:08 am

Dear Dirk,

An Oxygen installation only contains the mailapi.jar library in its libraries list (without any mail implementation).

So you should try to download the smtp.jar library from here:

https://java.net/projects/javamail/pages/Home#Download_JavaMail_Release

place it somewhere in your framework folder then edit your document type association and in the Classpath list add a reference to this additional library.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
DirkDubois
Posts: 22

Re: Mailapi.jar not working correctly

Wed Jun 17, 2015 4:13 pm

Thank you for the quick reply.

I added smtp.jar to the class path of the framework I am deploying, but when debugging the oxygen process, I still get the same error. Does this jar need to be integrated into the jar I provide oxygen with my custom author actions? Thanks for all your help.

Dirk
XML Programmer, Technical Writing
Matrox Imaging
Radu
Posts: 5757

Re: Mailapi.jar not working correctly

Wed Jun 17, 2015 4:19 pm

Hi Dirk,

As long as the JAR library is included in the Classpath list, it should be available for use in Author custom operations.
You say you get this error when debugging, do you get the same problem when running Oxygen with the framework deployed in it?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
DirkDubois
Posts: 22

Re: Mailapi.jar not working correctly

Thu Jun 18, 2015 6:05 pm

Hi Radu,

Thank you for the help I was able to resolve the problem. When I added both smtp-1.5.3.jar and mailapi-1.5.3.jar to the classpath of the framework before my CustomAuthorActions.jar, and I deployed the compiled version everything worked. For debugging, the solution was to add these same JARs to the class path of the debug configuration. This correctly resolved the issue. Thank you for all your help.

Thanks,
Dirk
XML Programmer, Technical Writing
Matrox Imaging

Return to “SDK-API, Frameworks - Document Types”

Who is online

Users browsing this forum: No registered users and 0 guests