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

你需要 WebDAV 支持来执行 MOVE ,检查Jackrabbit

于 2012-09-14T06:00:17.207 回答
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 回答