Search code examples
javascriptnode.jsasynchronousexchangewebservices

Is there a method to test Exchange connection?


I have to send some mail from a nodejs app and I'd like to throw an Exception from the constructor of the class that I'll use to handle mail if the credentials are wrong but I can't find a way to do this; I'm using the module ews-javascript-api to connect to the Exchange Server.

I've tried sending a test mail to a fake address but it won't work because the sender method returns a Promise from which I can't throw an exception.

class ExchSender{
    constructor(username, passowrd){
        this.exch = new ExchangeService();
        this.exch.Credentials = new ews.ExchangeCredentials(username, password);
        this.exch.Url = new Uri('https://exchange.exch/ews/exchange.asmx');

        //Here I'd like to test the connection and throw the exception
    }
}

Solution

  • If you just want to check the credentials then do a normal Get on the services.wsdl which will require authentication. This doesn't really check the Exchange connection just that IIS is available and the credentials work at the endpoint. A proper connection test would be see if you can Bind to the Inbox Folder as that would tell you that the Mailbox is available as there are many things on the backend where the IIS Endpoint is available be the store maybe offline, being moved or service is stop etc.