我正在尝试通过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>'
有人可以帮我吗?
答案 0 :(得分:0)
终于找到了这个错误的根本原因。通常,共享邮箱不需要任何许可证。我们要访问未经许可的邮箱时会发生Could not retrieve folders. ErrorNonExistentMailbox: No mailbox with such guid
错误。
当我尝试UserPrincipalName
而不是PrimarySmtpAddress
时,我能够访问邮箱。