Configure Niagara Ax to send Email.

The below steps explains how to configure the email service in Naigara Ax station, using its workbench. And below you will find the code to use the baja Email api to be able to send email in Niagara.

Navigate to BEmailService service under Station
Double click on the EmailService, you will find the Email Account Manager.
Click New Button
Provide the Outgoing Account information including the smtp server and port. And click ok.

email1

Now right click on the added account manager and choose Actions->Send
Now provide your email id information in from and to address fields. And click Ok.

In your station spy if you have enabled trace for module ‘email’. Then you can see the message below in station console.

 Code to Send Email

public void doSendEmail(){

 BEmailService bemailservice = 
 (BEmailService)Sys.getService(BEmailService.TYPE);
 bemailservice.lease(2);

 BOutgoingAccount outGoingAccount = 
 (BOutgoingAccount)bemailservice.getDefaultOutgoingAccount();

 if(outGoingAccount == null) {
  System.out.println("Email Service not configured")
  return;
 }
 BEmail mail = new BEmail();

 mail.setFrom(BEmailAddress.make("My Name", "myname@domain.com"));

 //Add to address
 List<BEmailAddress> toEmailList = new ArrayList<BEmailAddress>();
 toEmailList.add(BEmailAddress.make("Your Name","yourname@domain.com"));
 BEmailAddressList listEmail = BEmailAddressList.make(
    toEmailList.toArray(new BEmailAddress[toEmailList.size()])); 
 mail.setTo(listEmail);

 mail.setDate(BAbsTime.now());

 mail.setSubject("Test Subject");

 // Add attachment
 BEmailPartList part = new BEmailPartList();
 //part.addAttachment(BOrd.make("ord to attachement file"));
 mail.setAttachments(part);

 //Add body
 StringBuffer body = new StringBuffer();
 body.append("This is a test mail ");
 mail.setBody(new BTextPart(body.toString()));
//send mail
 outGoingAccount.send(mail);
}

 

Detailed description to configure Email can be found here.

 

Disclaimer: Niagara Ax tips in this website are sourced from the Open Niagara Ax online community http://www.niagara-central.com/ .   A forum where you can ask and resolve Niagara framework related queries.

Niagara Ax: How to programmatically get a module version

Here’s the code snippet to programmatically get a module’s version.

Sys.getRegistry().getModule("moduleName")
.getVendorVersion().toString();

Or if your class has a TYPE field

Sys.getRegistry().getModule(TYPE.getModule().getModuleName())
.getVendorVersion().toString();

This returns the vendorVersion value written in the module’s build.xml as shown below.

<module
	bajaVersion="3.4"
	description="Niagara Ax Module"
	edition="j2se-5.0"
	name="NiagaraModule"
	preferredSymbol="nm"
	vendor="Tridium Inc"
	vendorVersion="1.3.1"
>

Disclaimer: Niagara Ax tips in this website are sourced from the Open Niagara Ax online community http://www.niagara-central.com/ . A forum where you can ask and resolve Niagara framework related queries.

Niagara Ax: How to increase workbench client request timeout

When a Niagara workbench is connected to a remote supervisor, chances are there when client makes a request to the server, requests will be timed out after 1 minute or 60 seconds, because the server was taking more than 60 seconds to service the request.

Although Tridium will not encourage this, but we can increase the time out for clients in certain known scenarios. The file to be changed is %NIAGARA_HOME%/lib/system.properties

#UnComment the line below and provide a new value instead of 60000
niagara.fox.requestTimeout=60000

Disclaimer: Niagara Ax tips in this website are sourced from the Open Niagara Ax online community http://www.niagara-central.com/ . A forum where you can ask and resolve Niagara framework related queries.

Niagara Ax : Copy a BComponent to a bog file.

In Niagara Ax, a bog file is nothing but a zipped xml. Whenever we need to serialize a BComponent as a file in the station files structure, we can use the below code to achieve the same.

/**
 Copy a BComponent to a bogFile
 @param comp : The source component
 @param bogFile : The bogfile to be persisted to.
*/
 public static void copyComponentToBog(BComponent comp,BIFile bogFile) throws IOException {
      BogEncoder bogencoder = new  BogEncoder(bogFile.getOutputStream());
      bogencoder.setZipped(true);
      bogencoder.encodeDocument(comp);
      bogencoder.close();
    }

Vice-verse, to decode or convert a bog file to a component you can use BodDecoder class as shown below.

    /**
     * Decode a bog file and return its BComponent object.
     * @param sourceFile : The source bog file
     * @return BComponent
     * @throws Exception
     */
    public static BComponent bogFileToComponent(BIFile sourceFile throws Exception {
      BogDecoder bogDec = null;
      try{
          BogDecoder bogDec = new BogDecoder(file);
          BComponent component = ((BComponent)(bogDec.decodeDocument()));

         }finally{
          if(null != bogDec){
           bogDec.close();
          }
         }
      return component;
    }

Disclaimer: Niagara Ax tips in this website are sourced from the Open Niagara Ax online community http://www.niagara-central.com/ . A forum where you can ask and resolve Niagara framework related queries.