Home AMX User Forum Duet/Cafe Duet

amx_mail.jar

Does anybody know if I can access email services thru an OSGi bundle? or is there a different method of sending emails from Duet?

Comments

  • JasonSJasonS Posts: 229
    Further investigation

    After querying the Bundle for the amx_mail.jar file it does not report any Registered Services available thru OSGi. Is this only available to netlinx code? Does anyone know of a Duet module that sends emails? I don't know enough about OSGi to know wether I can just import the bundle. The Duet Manifest file configuration has a limited number of bundles? that can be imported, and I have not seen anyway to add to that list. I would prefer not to have to find a J2ME JDK 1.4 email client that is compatible, unless somebody has already been down this road?

    Frustrated again by AMX's lack of support for Duet, it was an exercise just getting the documentation I needed to start.
  • JasonSJasonS Posts: 229
    Anybody out there?

    I wrote some code that dumps all of the bundles and their registered services if anyone is interested. I also figured out how to manually add the amx_mail import to the manifest.duetmf file, but eclipse complains about not being able to resolve the packages when I import them in code. From what I have been reading about OSGi I think I might just need to import the jar into code and OSGi will simply not load it when the bundle is installed because it is already available in a bundle? In that case when I pack the module I could choose not to include the amx_mail.jar in my module jar? I am just speculating...
  • JasonSJasonS Posts: 229
    Finally got some information on amx_mail.jar. Here is some pseudo code for anyone interested.
    package com.example.duet.mail.test.dr1_0_0;
    
    import java.util.Properties;
    import org.osgi.framework.BundleContext;
    import com.amx.duet.da.NetLinxDevice;
    import com.amx.duet.devicesdk.Utility;
    
    import com.amx.mail.MailRef;
    import com.amx.mail.MailListener;
    
    public class MailTest extends Utility{
    
        MailRef amxMail = null;
        InnerMailListener mailListener = this.new InnerMailListener();
        Object callerData = newObject();
    
        public MailTest(BundleContext bctxt, NetLinxDevice nd, Properties props) {
            super(bctxt, nd, props);
            amxMail = new MailRef(bctxt, mailListener);
        }
    
        protected boolean doNetLinxDeviceInitialization() {
            amxMail.setServerName("your mail server name here");
            amxMail.setServerPort((char)your server port number);
            amxMail.setUsername("username");
            amxMail.setFromAddress("FromAddress");
            amxMail.setPassword("password");
            amxMail.send("toEmailAddress", "Subject", "Body", "text attachment fileame", callerData);
            //doNetLinxDeviceInitialization code
            return false; 
        }
    
        private class InnerMailListener implements MailListener {
    
            public void handleMailEvent(Object arg0, int arg1) {
                switch (arg1) {
                    case MailListener.cMailErrAuthFailure: {
                        System.out.println("Mail Error - Authentication Failure");
                    }
                    case MailListener.cMailErrMalformedData: {
                        System.out.println("Mail Error - Malformed Mail");
                    }
                    case MailListener.cMailErrNoMemory: {
                        System.out.println("Mail Error - Out of Memeory");
                    }
                    case MailListener.cMailErrProtocol: {
                        System.out.println("Mail Error - Protocol Error");
                    }
                    case MailListener.cMailErrServerUnreachable: {
                        System.out.println("Mail Error - Server Unreachable");
                    }
                    case MailListener.cMailErrUnknown: {
                        System.out.println("Mail Error - Unknown Error");
                    }
                }
            }
        }
    }
    
    

    Then in your manifest.duetmf file you need to add com.amx.mail under the import packages section. I left the version number field blank because it did not work with either of the 2 version numbers I tried "1.0.1" for the Bundle-Version or "1.12.0" for the Manifest-Version of amx_mail.jar. I added amx_mail.jar to my Duet project by right clicking the project in the Navigator, selecting "Java Build Path", then the "Libraries" tab and then the "Add External JARs..." button. This step made the com.amx.mail classes resolve in the ide so i could compile. Unless anyone at AMX objects I will post the amx_mail.jar file and the JavaDocs that I received thru my AMX rep.
Sign In or Register to comment.