Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor multiple mailbox #176

Closed
thlee927 opened this issue Apr 11, 2017 · 1 comment
Closed

Monitor multiple mailbox #176

thlee927 opened this issue Apr 11, 2017 · 1 comment
Assignees
Milestone

Comments

@thlee927
Copy link
Contributor

I have multiple mailbox, the auth method of these mailbox are different. (basic auth, NTLMv2 )
I can use this API (ews-javascript-api@0.9.0-dev.4, ews-javascript-api-auth@1.2.0) to monitor the mailbox as below cases:

  • multiple basic auth mailbox
  • single NTLMv2 mailbox

Here is my source code to create the service.

for loop mailBox start===>
    var ews = require('ews-javascript-api');
    ews.EwsLogging.DebugLogEnabled = false;
    var service = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
    var ewsAuth = require("./lib/ews-javascript-api-auth-ntlmv2/src/ntlmAuthXhrApi");
    var xhrHelper = new ewsAuth.ntlmAuthXhrApi(mailBox.AccountAddress, mailBox.AccountPassword);
    ews.ConfigurationApi.ConfigureXHR(xhrHelper);
    service.Credentials = new ews.ExchangeCredentials(mailBox.AccountAddress, mailBox.AccountPassword);
    service.Url = new ews.Uri(config.emailServer[mailBox.EmailServer]);
    //subscribe streaming notification
.........
<===== loop end 

When I try to monitor multiple NTLMv2 mailbox, it will throw an error. (Unhandled rejection Error: Invalid message signature)
I have check the source code, "ews.ConfigurationApi.ConfigureXHR" method is static. It only store the latest xhrHelper.

I found a workaround to handle this issue. Call "ews.ConfigurationApi.ConfigureXHR" method first, then call the bind method to retrieve the folder and email message.

function notificationEvent(mailBox, ews, xhrHelper){
    return function(streamingSubscriptionConnectionInstance, notificationEventArgs){
        var subscription = notificationEventArgs.Subscription;
        ews.ConfigurationApi.ConfigureXHR(xhrHelper);
        _.forEach(notificationEventArgs.Events, (notification) => {
            //winston.info(notification);
            if(notification instanceof ews.ItemEvent){                    
                var folder = null, email = null;
                ews.Folder.Bind(subscription.service, notification.parentFolderId).then((response)=>{
                    folder = response;
                    var additionalProps = [];
                    additionalProps.push(ews.ItemSchema.MimeContent);
                    additionalProps.push(ews.ItemSchema.UniqueBody);
                    var propertySet = new ews.PropertySet(ews.BasePropertySet.FirstClassProperties, additionalProps)
                    return ews.EmailMessage.Bind(subscription.service, notification.itemId, propertySet);
                }).then((response)=>{
                    email = response;
                    handleEmail(mailBox, notification, folder, email, ews);
                })
            }
        })
    };
}

But I have a concern on concurrent receive email case.
Do you have any suggestion to handle this case? Thanks

@gautamsi gautamsi self-assigned this Apr 11, 2017
@gautamsi gautamsi added this to the 1.1 milestone Apr 11, 2017
@gautamsi
Copy link
Owner

gautamsi commented Jul 1, 2017

you should be able to do this starting 0.9.0 see #180

@gautamsi gautamsi closed this as completed Jul 1, 2017
@gautamsi gautamsi modified the milestones: 0.9.0, 1.1 Jul 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants