获取访问被拒绝。检查凭据并使用交换重试,即使我们在交换时拥有有效的凭据

时间:2018-06-17 20:06:50

标签: outlook office365 exchangewebservices ewsjavaapi

我们正在使用ews api向电子邮件添加扩展属性“uniqueId”并使用它来检索电子邮件

   def sendEmail() :String = {

    val uId = getUniqueId();    

        val emailExtendedPropDef = new ExtendedPropertyDefinition(uId,"uniqueId", MapiPropertyType.String)
            try {
              email.setExtendedProperty(emailExtendedPropDef, uId.toString)
              email.sendAndSaveCopy()
            } catch {
              case e: Exception =>
                error(s"Exception in setting extended property for user $from", e)
                throw e
            }

      uId  
    }

一旦检索到电子邮件,我们希望继续删除扩展属性,这样我们就不会用完空间,现在删除工作正常,但偶尔我们会收到此异常..删除时

microsoft.exchange.webservices.data.core.exception.service.remote.ServiceResponseException: Access is denied. Check credentials and try again., Cannot save changes made to an item

不确定异常的原因是什么,因为我们能够成功删除大部分时间..所以它们肯定是有效的凭证,不确定它们为什么会变得无效并再次生效...

        def retreiveAndDeleteEmail(emailId: String): Option[EmailMessage] = {
            val propSetId = UUID.fromString(emailId)
            val view = new ItemView(5)
            val extendedPropDef = new ExtendedPropertyDefinition(uId,"uniqueId", MapiPropertyType.String)

            val filter = new IsEqualTo(emailIdPropDef, emailId)
            val propertySet = new PropertySet(BasePropertySet.FirstClassProperties, extendedPropDef)
            view.setPropertySet(propertySet)

            try {
              val result = service.findItems(WellKnownFolderName.SentItems, filter, view)
              if (result.getTotalCount > 0) {
                val success = safeLoadProperties(result, propertySet)

                if (success) {


                  deleteTheSetExtendedProperty(result, extendedPropDef)
                  val emails = result.getItems.asScala.flatMap(bindItem).collect {
                    case email: EmailMessage => email
                  }
                  return emails.headOption
                }
              }

              None
            } catch {
              case e: Exception =>
                error(s"Exception in deleting the extended property for user ", e)
                throw e
              case th: Throwable => None
            }
          }

          def deleteTheSetExtendedProperty(findResults : FindItemsResults[Item], extendedPropDef:ExtendedPropertyDefinition): Unit = {

            val item = findResults.getItems().get(0)

            if(item != null) {

              item.removeExtendedProperty(extendedPropDef)
              item.update(ConflictResolutionMode.AlwaysOverwrite)
            }

          }

如果有人能指出我们正确的方向,那将会有很大的帮助

0 个答案:

没有答案