2

我尝试使用以下代码使用 EWS Java API 发送邮件。但我收到选择 NTLM 身份验证的错误。我只需要基本身份验证。如何指定身份验证类型。

    ExchangeCredentials credentials = new WebCredentials("user", "pwd");
    service.setCredentials(credentials);
    try {
        service.setUrl(new java.net.URI("https://url/EWS/Exchange.asmx"));
        service.setTraceEnabled(true);

        EmailMessage msg = new EmailMessage(service);
        msg.setSubject("Hello world!");
        msg.setBody(MessageBody
                .getMessageBodyFromText("Sent using the EWS Managed API."));
        msg.getToRecipients().add("email");
        msg.send();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

请告诉我如何解决这个问题.... :(

4

1 回答 1

2

这取决于您交换服务器的配置。尝试使用可以在 Exchange 服务器上配置的不同用户名:

ExchangeService service = new ExchangeService();

ExchangeCredentials credentials = new WebCredentials("user@domain.com","pass");

或者

ExchangeCredentials credentials = new WebCredentials(Username,Password, domain);

或者

ExchangeCredentials credentials = new WebCredentials("user", "pwd");

service.setCredentials(credentials);

就我而言,起作用的是 Username,Password,Domain 方法。

于 2013-05-14T06:53:23.293 回答