我正在尝试通过 EWS 使用全局管理员帐户凭据获取邮箱文件夹。我正在使用以下带有视点 gem 的 ruby 脚本来执行此操作。
require 'viewpoint'
include Viewpoint::EWS
endpoint = 'https://outlook.office365.com/ews/exchange.asmx'
admin_email = 'admin@hostname.com'
password = 'password'
user_email = "user@hostname.com"
cli = Viewpoint::EWSClient.new endpoint, admin_email, password
cli.set_impersonation 'PrimarySmtpAddress', user_email #impersonation
act_as_hash = { act_as: user_email }
results = cli.folders(act_as_hash)
puts results.count
我已经为所有邮箱创建了所需的权限和模拟。访问共享邮箱时遇到问题。我可以使用相同的脚本访问用户邮箱文件夹。
当我尝试使用上述脚本获取共享邮箱文件夹时,出现以下错误。
/Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/connection.rb:121:in `check_response': SOAP Error: Message: The primary SMTP address must be specified when referencing a mailbox. Code: a:ErrorNonPrimarySmtpAddress (Viewpoint::EWS::Errors::SoapResponseError)
from /Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/connection.rb:103:in `post'
from /Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/connection.rb:81:in `dispatch'
from /Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/soap/exchange_web_service.rb:212:in `do_soap_request'
from /Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/soap/exchange_data_services.rb:503:in `find_folder'
from /Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/folder_accessors.rb:45:in `folders'
from o365_test_connection.rb:14:in `<main>'
我尝试评论模拟行并使用委派访问邮箱文件夹,但出现以下错误。
/Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/folder_accessors.rb:167:in `find_folders_parser': Could not retrieve folders. ErrorNonExistentMailbox: No mailbox with such guid. (Viewpoint::EWS::EwsFolderNotFound)
from /Users/yasitha/.rvm/gems/ruby-2.3.0/gems/viewpoint-1.1.0/lib/ews/folder_accessors.rb:46:in `folders'
from o365_test_connection.rb:14:in `<main>'
谁可以帮我这个事?