简体   繁体   中英

EWS fails with 'read ECONNRESET' on Jenkins

Using these libraries to connect to ews and get emails:

  • "ews-javascript-api": "^0.10.3"
  • "ews-javascript-api-auth": "^1.2.1"

Locally it works and I can connect to email boxes but when I run it on Jenkins I get this error:

SoapFaultDetails {
  message: 'read ECONNRESET',
  InnerException: null,
  faultCode: null,
  faultString: null,
  faultActor: null,
  responseCode: 127,
  errorCode: 0,
  exceptionType: null,
  lineNumber: 0,
  positionWithinLine: 0,
  errorDetails: DictionaryWithStringKey {
    keys: [],
    keysToObjs: {},
    objects: {},
    keyPicker: [Function (anonymous)]
  },
  HttpStatusCode: undefined
}

A function which connects and read the email:

function getEws(user, password, host, subject) {

  ews.ConfigurationApi.ConfigureXHR(new ewsAuth.ntlmAuthXhrApi(user, password))
  const service = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013_SP1)
  service.Credentials = new ews.WebCredentials(user, password)
  service.Url = new ews.Uri(host)

  service
    .SubscribeToStreamingNotifications(
      [new ews.FolderId(ews.WellKnownFolderName.Inbox)],
      ews.EventType.NewMail,
      ews.EventType.Created,
      ews.EventType.Deleted,
      ews.EventType.Modified,
      ews.EventType.Moved,
      ews.EventType.Copied,
      ews.EventType.FreeBusyChanged
    )
    .then(function (streamingSubscription) {
      var connection = new ews.StreamingSubscriptionConnection(service, 1)
      connection.AddSubscription(streamingSubscription)
      connection.OnNotificationEvent.push(function (obj) {
        ews.EwsLogging.Log(obj, true, true)
        const searchFilter = new ews.SearchFilter.SearchFilterCollection(ews.LogicalOperator.And, [
          new ews.SearchFilter.ContainsSubstring(ews.ItemSchema.Subject, subject)
        ])

        const itemview = new ews.ItemView(1)

        const foundItems = service.FindItems(ews.WellKnownFolderName.Inbox, searchFilter, itemview)

        const adinationalProps = []
        adinationalProps.push(ews.ItemSchema.TextBody)

        foundItems.then(function (response) {
          for (const item of response.Items) {
            item
              .Load(new ews.PropertySet(ews.BasePropertySet.FirstClassProperties, adinationalProps))
              .then(function () {
                fs.writeFileSync('cypress/fixtures/email.txt', item.TextBody.text)
              })
              .catch(error => {
                console.log(' ----- Load error start ----- ')
                console.error(error)
                console.log(' ----- Load error end ----- ')
              })
          }
        })
      })
      connection.OnDisconnect.push(function (connection, subscriptionErrorEventArgsInstance) {
        ews.EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true)
      })
      connection.Open()
    })
    .catch(error => {
      console.log(' ----- SubscribeToStreamingNotifications error start ----- ')
      console.error(error)
      console.log(' ----- SubscribeToStreamingNotifications error end ----- ')
    })
}

I would be grateful for any ideas on how to solve this issue on Jenkins.

That was an issue with expired SSL certificates on Travis's side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM