Я пытаюсь использовать API ews-java для подключения к моему почтовому ящику и прослушивания новых писем.прослушать новое письмо на бирже
я, кажется, чтобы быть в состоянии соединить очень хорошо, и я копирую код из примеров на GitHub здесь:
// Subscribe to push notifications on the Inbox folder, and only listen
// to "new mail" events.
PushSubscription pushSubscription = service.SubscribeToPushNotifications(
new FolderId[] { WellKnownFolderName.Inbox },
new Uri("https://...") /* The endpoint of the listener. */,
5 /* Get a status event every 5 minutes if no new events are available. */,
null /* watermark: null to start a new subscription. */,
EventType.NewMail);
Однако это ошибка в затмении:
new FolderId[] { WellKnownFolderName.Inbox }, // <---TYPE MISMATCH - CANNOT CONVERT FRM
WELLKNOWNFOLDERNAME TO FOLDERID
А также
EventType.NewMail); // <---- NEWMAIL CANNOT BE RESOLVED OR IS NOT A FIELD
Его трудно разобраться в этом, потому что я не могу найти руководство по всем методам для этой библиотеки - и пример не работает.
Полный код:
package com.geekhelp.quickstart;
import javax.swing.event.DocumentEvent.EventType;
import microsoft.exchange.webservices.data.autodiscover.IAutodiscoverRedirectionUrl;
import microsoft.exchange.webservices.data.core.ExchangeService;
import microsoft.exchange.webservices.data.core.enumeration.misc.ExchangeVersion;
import microsoft.exchange.webservices.data.core.enumeration.property.WellKnownFolderName;
import microsoft.exchange.webservices.data.core.service.item.EmailMessage;
import microsoft.exchange.webservices.data.core.service.item.Item;
import microsoft.exchange.webservices.data.credential.ExchangeCredentials;
import microsoft.exchange.webservices.data.credential.WebCredentials;
import microsoft.exchange.webservices.data.notification.PushSubscription;
import microsoft.exchange.webservices.data.property.complex.FolderId;
import microsoft.exchange.webservices.data.property.complex.MessageBody;
import microsoft.exchange.webservices.data.search.FindItemsResults;
import microsoft.exchange.webservices.data.search.ItemView;
public class App {
public static void main(String[] args) {
System.out.println("Running");
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
ExchangeCredentials credentials = new WebCredentials("[email protected]", "test");
service.setCredentials(credentials);
try {
service.autodiscoverUrl("[email protected]");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Hello World");
EmailMessage message;
try {
message = new EmailMessage(service);
message.getToRecipients().add("[email protected]");
message.setSubject("attachements");
message.setBody(MessageBody.getMessageBodyFromText("Email attachements"));
message.send();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Subscribe to push notifications on the Inbox folder, and only listen
// to "new mail" events.
PushSubscription pushSubscription = service.SubscribeToPushNotifications(
new FolderId[] { WellKnownFolderName.Inbox }, // <------------ TYPE MISMATCH - CANNOT CONVERT FRM
WELLKNOWNFOLDERNAME TO FOLDERID
new java.net.URI("https://mail.test.com//EWS//Exchange.asmx") /* The endpoint of the listener. */,
5 /* Get a status event every 5 minutes if no new events are available. */,
null /* watermark: null to start a new subscription. */,
EventType.NewMail); // <----------- NEWMAIL CANNOT BE RESOLVED OR IS NOT A FIELD
}
Спасибо.
UPDATE
Спасибо, но я все еще получаю ошибку:
FolderId[] folderId = { new FolderId(WellKnownFolderName.Inbox)};
PushSubscription pushSubscription = service.subscribeToPushNotifications(folderId , service.getUrl(), 5, null, EventType.NewMail);
subscribeToPushNotifications подчеркнут красным цветом, а IDE говорит:
Метод subscribeToPushNotifications (Iterable, URI, INT, String, EventType ...) в типе ExchangeService не применим для аргументов (FolderId [], URI, int, null, EventType)