使用 EWS 托管 API 创建共享邮箱

Posted

技术标签:

【中文标题】使用 EWS 托管 API 创建共享邮箱【英文标题】:Create a shared mailbox with EWS Managed API 【发布时间】:2017-11-19 22:58:45 【问题描述】:

如何连接到 Exchange 服务器并创建共享邮箱。我找不到使用 AWS Managed API 的方法。有什么建议么?谢谢。

【问题讨论】:

【参考方案1】:

好吧,我找到了方法,如果有人需要,这就是解决方案(从控制台应用程序执行 cmdlet):

public class Service

    public static ExchangeService GetExchangeService(string username, string password, string ExchangeUrl)
    
        var exchangeService = new ExchangeService(ExchangeVersion.Exchange2013);

        //WebService Uri
        try
        
            exchangeService.Url = new Uri(ExchangeUrl);
        
        catch (Exception ex)
        
            throw new Exception(string.Format("WebService Uri:" + ex));
        

        //Credentials
        try
        
            exchangeService.Credentials = new WebCredentials(username, password);
        
        catch (Exception ex)
        
            throw new Exception(string.Format("Credentials:" + ex));
        
        return exchangeService;
    


 static void Main(string[] args)
    
        ExchangeService service = null;
        service = Service.GetExchangeService("email@myexchangedomain.com", "mypassword", "https://outlook.office365.com/EWS/Exchange.asmx");

      var emailCreateCommand = CreateEmailCommand("name", "displayName", "alias");
      var res2 = ExecuteCommand(emailCreateCommand);

     


private static Command CreateEmailCommand(string name, string displayName, string alias)
    
        Command myCommand = new Command("New-MailBox");
        myCommand.Parameters.Add("Shared", true);
        myCommand.Parameters.Add("Name", name);
        myCommand.Parameters.Add("DisplayName", displayName);
        myCommand.Parameters.Add("Alias", alias);

        return myCommand;
    



public static Collection<PSObject> ExecuteCommand(Command command)
    
        string pass = "mypassword";
        System.Security.SecureString securePassword = new System.Security.SecureString();

        foreach (char c in pass.ToCharArray())
        
            securePassword.AppendChar(c);
        

        PSCredential newCred = new PSCredential("email@myexchangedomain.com", securePassword);


        WSManConnectionInfo connectionInfo = new WSManConnectionInfo(
            new Uri("https://outlook.office365.com/PowerShell-LiveID"),
            "http://schemas.microsoft.com/powershell/Microsoft.Exchange",
            newCred);

        connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;

        Runspace myRunSpace = RunspaceFactory.CreateRunspace(connectionInfo);
        myRunSpace.Open();

        Pipeline pipeLine = myRunSpace.CreatePipeline();

        pipeLine.Commands.Add(command);
        Collection<PSObject> result = pipeLine.Invoke();
        myRunSpace.Close();
        return result;
    

【讨论】:

以上是关于使用 EWS 托管 API 创建共享邮箱的主要内容,如果未能解决你的问题,请参考以下文章

使用 EWS 托管 API 读取自定义列

o365 和 Exchange 2010 的 EWS 托管 API 的 OAuth 身份验证

Powershell EWS 从共享邮箱发送电子邮件

C# Managed EWS 通过 ID 从共享邮箱获取电子邮件

EWS:来自日历 FolderId 的邮箱地址,这可能吗?

使用 EWS 访问通用流程收件箱