以下是我用于使用EWS for Android发送邮件的代码。
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
ExchangeCredentials credentials = new WebCredentials("user","pass");
service.setCredentials(credentials);
service.setUrl(new URI("https://valid_server/ews/Exchange.asmx"));
EmailMessage msg= new EmailMessage(service);
msg.setSubject("Hello world!");
msg.setBody(MessageBody.getMessageBodyFromText("Sent using the EWS Java API."));
msg.getToRecipients().add("myemail");
msg.send();
然而它无效,我收到以下错误。任何人都可以告诉我这件事。
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ java.lang.NullPointerException: format == null
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at java.lang.String.format(String.java:1799)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at java.lang.String.format(String.java:1777)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.ServiceRequestBase.getEwsHttpWebResponse(ServiceRequestBase.java:936)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.ServiceRequestBase.validateAndEmitRequest(ServiceRequestBase.java:821)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:46)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:143)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.ExchangeService.internalCreateItems(ExchangeService.java:463)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.ExchangeService.createItem(ExchangeService.java:534)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.Item.internalCreate(Item.java:215)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.EmailMessage.internalSend(EmailMessage.java:125)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at microsoft.exchange.webservices.data.EmailMessage.send(EmailMessage.java:253)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at com.example.test.MainActivity$EWSOperation.doInBackground(MainActivity.java:61)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at com.example.test.MainActivity$EWSOperation.doInBackground(MainActivity.java:39)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at android.os.AsyncTask$2.call(AsyncTask.java:292)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at java.util.concurrent.FutureTask.run(FutureTask.java:237)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-12 03:26:00.411 18432-18457/com.example.test W/System.err﹕ at java.lang.Thread.run(Thread.java:818)