1

Java HttpClient 4.x を使用して Outlook コネクタ用のライブラリを作成しています。アプリケーションからメールを送信する必要があります。メッセージを下書きフォルダーに入れることができます。しかし、どうすれば受信者に送信できますか。ここに私が試したコードがあります`

    String strTempURI = "https://" + serverName + "/exchange/" + Username
            + "/drafts/" +strSubject + "eml";
    String strSubURI = "https://" + serverName + "/exchange/" + Username
            + "/##DavMailSubmissionURI##/";

    URI uri=new URI(strTempURI);
    HttpPut put = new HttpPut(uri);
    ByteArrayEntity entity = new ByteArrayEntity(byteout1);
    DefaultHttpClient client =new DefaultHttpClient();
    HttpContext localContext = new BasicHttpContext();
    CredentialsProvider credsProvider = new BasicCredentialsProvider();
    credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,    
                  AuthScope.ANY_PORT,AuthScope.ANY_REALM, AuthPolicy.BASIC),
                new UsernamePasswordCredentials(Username, password));

   client.setCredentialsProvider(credsProvider);
   put.setHeader("Content-Type", "message/rfc822");
   put.setEntity(entity);
   localContext.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
   HttpResponse response=client.execute(put,localContext);
   HttpEntity resEntity = response.getEntity();
   String result = EntityUtils.toString(resEntity);

「byteout1」にはメールの内容が含まれます。client.execute() の後、コンテンツを「strSubURI」に移動したい

4

2 に答える 2

0

これが私の質問に対する答えです。jutsを使用してMoveMethod(sourceurl、desturl)を作成します

String strTempURI = "https://" + serverName + "/exchange/" + Username
        + "/drafts/" +strSubject + "eml";
String strSubURI = "https://" + serverName + "/exchange/" + Username
        + "/##DavMailSubmissionURI##/";

URI uri=new URI(strTempURI);
HttpPut put = new HttpPut(uri);
ByteArrayEntity entity = new ByteArrayEntity(byteout1);
DefaultHttpClient client =new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(AuthScope.ANY_HOST,    
              AuthScope.ANY_PORT,AuthScope.ANY_REALM, AuthPolicy.BASIC),
            new UsernamePasswordCredentials(Username, password));

client.setCredentialsProvider(credsProvider);
put.setHeader("Content-Type", "message/rfc822");
put.setEntity(entity);
localContext.setAttribute(ClientContext.CREDS_PROVIDER, credsProvider);
HttpResponse response=client.execute(put,localContext);
HttpEntity resEntity = response.getEntity();
String result = EntityUtils.toString(resEntity);

 MoveMethod move = new MoveMethod(uri.toString(), strSubURI);
        move.setHeader("Destination", strSubURI);
        HttpResponse status = client.execute(move);
于 2012-09-17T06:14:57.340 に答える
0

MOVE を実行するには WebDAV サポートが必要です。Jackrabbitをチェックアウトしてください。

于 2012-09-14T06:00:17.207 に答える