Configure Niagara Ax to send Email. 3

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.

Please like & share:

3 thoughts on “Configure Niagara Ax to send Email.

  1. Reply Suresh Mar 8,2013 4:01 pm

    Great ! Thank you.

  2. Reply Ruban Mar 15,2013 6:57 pm

    Thank you.

  3. Reply agen ceme Aug 30,2015 7:51 pm

    Fantastic website you have here but I was wondering
    if you knew of any discussion boards that cover the same topics discussed here?
    I’d really love to be a part of group where I can get feed-back from other experienced people that share the same
    interest. If you have any suggestions, please let me know.

Leave a Reply

  

  

  


*