2016-08-24 4 views
0

ews-java APIを使用して受信トレイに接続し、新しいメールを受信しようとしています。交換時に新しいメールを受信します

私はうまく接続できているようだ、と私はここにgithubの上の例からコードをコピーしています:

https://github.com/OfficeDev/ews-java-api/wiki/Getting-Started-Guide#beginsubscribetopushnotifications

// 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); 

しかし、これはEclipseでエラーです:

new FolderId[] { WellKnownFolderName.Inbox }, // <---TYPE MISMATCH - CANNOT CONVERT FRM 
WELLKNOWNFOLDERNAME TO FOLDERID 

また、

EventType.NewMail); // <---- NEWMAIL CANNOT BE RESOLVED OR IS NOT A FIELD 

このlibのすべてのメソッドについてマニュアルを見つけることができないので、これを整理するのは難しいです。この例はうまくいきません。

完全なコードは次のとおりです。

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(反復処理可能な、URI、int型、 String、EventType ...)は、引数(FolderId []、URI、int、null、EventType)には適用されません。

答えて

1

Tw o事:

1)WellKnownFolderNameからFolderIdを作成するには、relevant constructorを使用する必要があります。だから、変更: new FolderId[] { WellKnownFolderName.Inbox }へ:

new FolderId[] { new FolderId(WellKnownFolderName.Inbox) }

注:new FolderId[] {..}は配列を作成します。配列の各項目はFolderId型でなければならないので、コンストラクタnew FolderId(...)を使用し、WellKnownFolderNameを引数として渡します。

2)あなたはIDEの自動インポート機能の間違ったEventType(おそらく障害をインポートしている)、
だから変更: import javax.swing.event.DocumentEvent.EventType;へ:

import microsoft.exchange.webservices.data.core.enumeration.notification.EventType;

関連する問題