日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪(fǎng)問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

java调用outlook

發(fā)布時(shí)間:2024/4/17 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java调用outlook 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

http://uule.iteye.com/blog/1195597

Java代碼 ?
  • package?test; ??
  • import?java.io.BufferedReader; ??
  • ??
  • public?class?TestMail?{ ??
  • ??
  • ????public?static?void?main(String[]?args)?throws?Exception?{ ??
  • ????????/*String?body?=?"<div?style='color:red;'>This?is?a?Test?!</div>"; ?
  • ????????Runtime.getRuntime().exec("D:\\Program?Files\\Microsoft?Office\\Office14\\OUTLOOK.EXE??mailto:KO@techson.com.hk?subject=Chinese?New?Year?backup?arrangement"?+ ?
  • ????????????????"&cc=Ko@techson.com.hk&body="+body);*/??
  • ???????? ??
  • ????????//System.out.println(System.getProperty("java.library.path"));?? ??
  • ???????? ??
  • ???????????ActiveXComponent?axOutlook?=?new?ActiveXComponent("Outlook.Application");?? ??
  • ???????????//Dispatch?ds?=?axOutlook.getObject(); ??
  • ??????????/*?Dispatch?namespace?=?Dispatch.call(axOutlook,?"GetNamespace",?"MAPI").toDispatch()?; ?
  • ???????????String?path?=?new?File("F:/test.htm").getAbsolutePath();? ?
  • ???????????Dispatch?mailItem?=?Dispatch.call(namespace,?"OpenSharedItem",?path).toDispatch();?*/??
  • ??????????? ??
  • ??????????? ??
  • ???????????Dispatch?mailItem?=?Dispatch.call(axOutlook,?"CreateItem",?0).getDispatch();?? ??
  • ??????????? ??
  • ???????????//Dispatch?mailItem?=?Dispatch.call(axOutlook,?"Open",?"F:/test.htm").toDispatch(); ??
  • ??????????//?Dispatch?body?=?Dispatch.call(mailItem,?"Body").getDispatch();;?? ??
  • ??????????//?Dispatch.call(body,?"Copy"); ??
  • ??????????? ??
  • ???????????Dispatch?inspector?=?Dispatch.get(mailItem,?"GetInspector").getDispatch(); ??
  • ??
  • ???????????//收件人?? ??
  • ???????????Dispatch?recipients?=?Dispatch.call(mailItem,?"Recipients").getDispatch();?? ??
  • ???????????Dispatch.call(recipients,?"Add"?,?"crycbj@163.com");?? ??
  • ???????????//郵件主題?? ??
  • ???????????Dispatch.put(mailItem,?"Subject",?"Test5!");?? ??
  • ???????????Dispatch.put(mailItem,?"CC",?"1@qq.com");?? ??
  • ???????????//Dispatch.put(mailItem,?"CC",?"cry@163.com");?? ??
  • ???????????//Dispatch.put(mailItem,?"ReadReceiptRequested",?"false");? ??
  • ??????????? ??
  • ???????????String?body?=?"<html><body><div?style='color:red;'>This?is?a?Test?!</div></body></html>"; ??
  • ???????????//Dispatch.put(mailItem,?"HTMLBody",?body);? ??
  • ??????????? ??
  • ??????????//?File?file?=?new?File("C:/test.htm"); ??
  • //?????????FileOutputStream?f?=?new?FileOutputStream("F:/test.htm"); ??
  • //?????????f.write(body.getBytes()); ??
  • //?????????f.close(); ??
  • ??????????? ??
  • ???????????BufferedReader?bf?=?new?BufferedReader(new?FileReader(new?File("F:/Ro.htm"))); ??
  • ???????????String?html?=?""; ??
  • ???????????String?str?=?""; ??
  • ???????????while(?(str=bf.readLine())?!=?null){ ??
  • ???????????????html?+=?str; ??
  • ???????????} ??
  • ???????????Dispatch.put(mailItem,?"HTMLBody",?html);? ??
  • ??????????? ??
  • ???????????//Dispatch?bodyDis?=?Dispatch.get(mailItem,?"Body").toDispatch();?? ??
  • ???????????//Dispatch.call(bodyDis,?"Add"?,?"F:/test.htm");?? ??
  • ???????????//Dispatch.put(mailItem,?"Body",?new?Variant("F:/test.htm"));?? ??
  • ??????????? ??
  • ???????????//Dispatch.put(mailItem,?"Body",?body);?? ??
  • ???????????//Dispatch.call(mailItem,?"InsertAfter",body?);//插入一個(gè)段落 ??
  • ??????????? ??
  • ???????????//Dispatch?selection?=?Dispatch.get(axOutlook,?"Selection").toDispatch(); ??
  • ??????????? ??
  • ???????????//Dispatch?inHtmleditor?=?Dispatch.call(inspector,?"HTMLEditor").getDispatch(); ??
  • ??????????//?Dispatch.call(inHtmleditor,?"Paste").getDispatch();?? ??
  • ???????????//Dispatch.invoke(inHtmleditor,?"Paste",?Dispatch.Method,?new?Object[]{false},?new?Variant(false)); ??
  • ??????????? ??
  • ???????????//附件?? ??
  • //?????????????Dispatch?attachments?=?Dispatch.call(mailItem,?"Attachments").getDispatch();?? ??
  • //?????????????Dispatch.call(attachments,?"Add"?,?"D:\\20110127.txt");?? ??
  • //?????????????Dispatch.call(attachments,?"Add"?,?"D:\\20110128.txt");?? ??
  • ???????????//顯示新郵件窗口?? ??
  • ??????????? ??
  • ???????????Dispatch.call(mailItem,?"Display");?? ??
  • ???????????Dispatch.call(mailItem,?"Send");?? ??
  • ??????????? ??
  • ??????????? ??
  • ????} ??
  • }??
  • package test; import java.io.BufferedReader;public class TestMail {public static void main(String[] args) throws Exception {/*String body = "<div style='color:red;'>This is a Test !</div>";Runtime.getRuntime().exec("D:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.EXE mailto:KO@techson.com.hk?subject=Chinese New Year backup arrangement" +"&cc=Ko@techson.com.hk&body="+body);*///System.out.println(System.getProperty("java.library.path")); ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application"); //Dispatch ds = axOutlook.getObject();/* Dispatch namespace = Dispatch.call(axOutlook, "GetNamespace", "MAPI").toDispatch() ;String path = new File("F:/test.htm").getAbsolutePath(); Dispatch mailItem = Dispatch.call(namespace, "OpenSharedItem", path).toDispatch(); */Dispatch mailItem = Dispatch.call(axOutlook, "CreateItem", 0).getDispatch(); //Dispatch mailItem = Dispatch.call(axOutlook, "Open", "F:/test.htm").toDispatch();// Dispatch body = Dispatch.call(mailItem, "Body").getDispatch();; // Dispatch.call(body, "Copy");Dispatch inspector = Dispatch.get(mailItem, "GetInspector").getDispatch();//收件人 Dispatch recipients = Dispatch.call(mailItem, "Recipients").getDispatch(); Dispatch.call(recipients, "Add" , "crycbj@163.com"); //郵件主題 Dispatch.put(mailItem, "Subject", "Test5!"); Dispatch.put(mailItem, "CC", "1@qq.com"); //Dispatch.put(mailItem, "CC", "cry@163.com"); //Dispatch.put(mailItem, "ReadReceiptRequested", "false"); String body = "<html><body><div style='color:red;'>This is a Test !</div></body></html>";//Dispatch.put(mailItem, "HTMLBody", body); // File file = new File("C:/test.htm"); // FileOutputStream f = new FileOutputStream("F:/test.htm"); // f.write(body.getBytes()); // f.close();BufferedReader bf = new BufferedReader(new FileReader(new File("F:/Ro.htm")));String html = "";String str = "";while( (str=bf.readLine()) != null){html += str;}Dispatch.put(mailItem, "HTMLBody", html); //Dispatch bodyDis = Dispatch.get(mailItem, "Body").toDispatch(); //Dispatch.call(bodyDis, "Add" , "F:/test.htm"); //Dispatch.put(mailItem, "Body", new Variant("F:/test.htm")); //Dispatch.put(mailItem, "Body", body); //Dispatch.call(mailItem, "InsertAfter",body );//插入一個(gè)段落//Dispatch selection = Dispatch.get(axOutlook, "Selection").toDispatch();//Dispatch inHtmleditor = Dispatch.call(inspector, "HTMLEditor").getDispatch();// Dispatch.call(inHtmleditor, "Paste").getDispatch(); //Dispatch.invoke(inHtmleditor, "Paste", Dispatch.Method, new Object[]{false}, new Variant(false));//附件 // Dispatch attachments = Dispatch.call(mailItem, "Attachments").getDispatch(); // Dispatch.call(attachments, "Add" , "D:\\20110127.txt"); // Dispatch.call(attachments, "Add" , "D:\\20110128.txt"); //顯示新郵件窗口 Dispatch.call(mailItem, "Display"); Dispatch.call(mailItem, "Send"); } }

    ?調(diào)用Word:

    http://www.360doc.com/content/07/0330/15/23378_421609.shtml

    http://www.360doc.com/content/11/0130/19/3947093_90007570.shtml

    http://www.th7.cn/Program/java/2011/10/12/43708.shtml

    ?

    基本語(yǔ)法:

    http://hi.baidu.com/meng_fy/blog/item/d7186116a409ae17972b43df.html

    http://java.chinaitlab.com/tools/769980.html

    http://www.ibm.com/developerworks/cn/java/j-lo-jacob/

    ?

    Java代碼 ?
  • package?test; ??
  • ??
  • import?java.io.File; ??
  • ??
  • public?class?TestMail2?{ ??
  • ??
  • ????/** ?
  • ?????*?@param?args ?
  • ?????*/??
  • ????public?static?void?main(String[]?args)?{ ??
  • ????????ActiveXComponent?xl?=?new?ActiveXComponent("Outlook.Application"); ??
  • ??
  • ????????Dispatch?explorer?=?Dispatch.get(xl,"ActiveExplorer").toDispatch(); ??
  • ????????Dispatch?selection?=?Dispatch.get(explorer,?"Selection").toDispatch(); ??
  • ????????Variant?count?=?Dispatch.get(selection,?"Count"); ??
  • ??
  • ????????for?(int?mailIndex?=?1;?mailIndex?<=?count.toInt();?mailIndex++?)?{ ??
  • ????????????Dispatch?mailItem?=?Dispatch.call(selection,?"Item",?new?Variant(mailIndex)).toDispatch(); ??
  • ??
  • ????????????Variant?senderName?=?Dispatch.get(mailItem,?"SenderName"); ??
  • ????????????Variant?subject?=?Dispatch.get(mailItem,?"Subject"); ??
  • ????????????Variant?body?=?Dispatch.get(mailItem,?"HTMLBody"); ??
  • ???? ??
  • ????????????String?emailFileName?=?subject.toString()?+".txt";?? ??
  • ???????????? ??
  • ????????????try?{ ??
  • ????????????????File?email?=?new?File(emailFileName); ??
  • ????????????????PrintWriter?writer?=?new?PrintWriter(?new?FileWriter(email)?); ??
  • ????????????????writer.println("From:?"+?senderName?); ??
  • ????????????????writer.println("Subject:?"+?subject); ??
  • ????????????????writer.println(""); ??
  • ????????????????writer.print(?body?); ??
  • ????????????????writer.close(); ??
  • ????????????} ??
  • ????????????catch?(IOException?e)?{ ??
  • ????????????????System.out.println("IOException?writing?e-mail?with?subject:?'"+?subject?+"'"); ??
  • ????????????????continue; ??
  • ????????????} ??
  • ??
  • ????????????Dispatch?attachments?=?Dispatch.get(mailItem,?"Attachments").toDispatch(); ??
  • ????????????Variant?attachmentCount?=?Dispatch.get(attachments,?"Count"); ??
  • ??
  • ????????????if?(?attachmentCount.toInt()?>?0?)?{ ??
  • ????????????????for(?int?attachmentIndex?=?1;?attachmentIndex<=attachmentCount.toInt();?attachmentIndex++?)?{ ??
  • ????????????????????Dispatch?attachment?=?Dispatch.call(attachments,?"Item",?new?Variant(attachmentIndex)).toDispatch(); ??
  • ????????????????????Variant?fileNameVariant?=?Dispatch.get(attachment,?"FileName"); ??
  • ????????????????????String?fileName?=?fileNameVariant.toString(); ??
  • ???????????? ??
  • ????????????????????Variant?saveResult?=?Dispatch.call(attachment,?"SaveAsFile",?"F:\\"+fileName); ??
  • ????????????????} ??
  • ????????????} ??
  • ???????? ??
  • ????????} ??
  • ????} ??
  • ??
  • }??
  • package test;import java.io.File;public class TestMail2 {/*** @param args*/public static void main(String[] args) {ActiveXComponent xl = new ActiveXComponent("Outlook.Application");Dispatch explorer = Dispatch.get(xl,"ActiveExplorer").toDispatch();Dispatch selection = Dispatch.get(explorer, "Selection").toDispatch();Variant count = Dispatch.get(selection, "Count");for (int mailIndex = 1; mailIndex <= count.toInt(); mailIndex++ ) {Dispatch mailItem = Dispatch.call(selection, "Item", new Variant(mailIndex)).toDispatch();Variant senderName = Dispatch.get(mailItem, "SenderName");Variant subject = Dispatch.get(mailItem, "Subject");Variant body = Dispatch.get(mailItem, "HTMLBody");String emailFileName = subject.toString() +".txt"; try {File email = new File(emailFileName);PrintWriter writer = new PrintWriter( new FileWriter(email) );writer.println("From: "+ senderName );writer.println("Subject: "+ subject);writer.println("");writer.print( body );writer.close();}catch (IOException e) {System.out.println("IOException writing e-mail with subject: '"+ subject +"'");continue;}Dispatch attachments = Dispatch.get(mailItem, "Attachments").toDispatch();Variant attachmentCount = Dispatch.get(attachments, "Count");if ( attachmentCount.toInt() > 0 ) {for( int attachmentIndex = 1; attachmentIndex<=attachmentCount.toInt(); attachmentIndex++ ) {Dispatch attachment = Dispatch.call(attachments, "Item", new Variant(attachmentIndex)).toDispatch();Variant fileNameVariant = Dispatch.get(attachment, "FileName");String fileName = fileNameVariant.toString();Variant saveResult = Dispatch.call(attachment, "SaveAsFile", "F:\\"+fileName);}}}}}

    ?

    Java代碼 ?
  • package?test; ??
  • ??
  • import?com.jacob.activeX.ActiveXComponent; ??
  • import?com.jacob.com.Dispatch; ??
  • ??
  • public?class?TestMail3?{ ??
  • ??
  • ????/** ?
  • ?????*?@param?args ?
  • ?????*/??
  • ????public?static?void?main(String[]?args)?{ ??
  • ????????final?int?olFolderContacts?=?10; ??
  • ??
  • ????????ActiveXComponent?ol?=?new?ActiveXComponent("Outlook.Application"); ??
  • ???????? ??
  • ????????Dispatch?olo?=?ol.getObject(); ??
  • ????????Dispatch?myNamespace?=?Dispatch.call(olo,?"GetNamespace","MAPI").toDispatch(); ??
  • ????????Dispatch?myFolder?=?Dispatch.call(myNamespace,?"GetDefaultFolder",new?Integer(olFolderContacts)).toDispatch(); ??
  • ??
  • ????????//n?chste?zeile?Fehlermeldung ??
  • ??
  • ????????Dispatch?items?=?Dispatch.get(myFolder,?"Items").toDispatch(); ??
  • ??
  • ????????int?count?=?Dispatch.call(items,?"Count").toInt(); ??
  • ??
  • ????????for?(int?i?=?1;?i?<=?count;?i++)?{ ??
  • ????????????Dispatch?item; ??
  • ????????????item?=?Dispatch.call(items,?"Item",?new?Integer(i)).toDispatch(); ??
  • ???? ??
  • ????????????String?fullName?=?Dispatch.get(item,?"Fullname").toString(); ??
  • ????????????String?emailAddress?=?Dispatch.get(item,?"Email1Address").toString(); ??
  • ????????????String?addressStreet?=?Dispatch.get(item,?"BusinessAddressStreet").toString(); ??
  • ????????????String?addressCity?=?Dispatch.get(item,?"BusinessAddressCity").toString(); ??
  • ????????????String?addressCountry?=?Dispatch.get(item,?"BusinessAddressCountry").toString(); ??
  • ????????????String?addressPostalCode?=?Dispatch.get(item,"BusinessAddressPostalCode").toString(); ??
  • ????????????String?addressState?=?Dispatch.get(item,?"BusinessAddressState").toString(); ??
  • ????????????String?title?=?Dispatch.get(item,?"Title").toString(); ??
  • ????????????String?phone?=?Dispatch.get(item,?"BusinessTelephoneNumber").toString(); ??
  • ????????????String?fax?=?Dispatch.get(item,?"BusinessFaxNumber").toString(); ??
  • ???? ??
  • ????????????printField("",?fullName); ??
  • ????????????printField("",?title); ??
  • ????????????printField("",?addressStreet); ??
  • ????????????printField("",?addressCity); ??
  • ????????????printField("",?addressState); ??
  • ????????????printField("",?addressPostalCode); ??
  • ????????????printField("",?addressCountry); ??
  • ????????????printField("Tel:",?phone); ??
  • ????????????printField("Fax:",?fax); ??
  • ????????????printField("Email:",?emailAddress); ??
  • ???? ??
  • ????????????System.out.println(); ??
  • ????????} ??
  • ????} ??
  • ??
  • ????????public?static?void?printField(String?label,?String?value)?{ ??
  • ????????????if?(value.length()?!=?0)?{ ??
  • ????????????????System.out.println(label?+?"?"?+?value); ??
  • ????????????} ??
  • ????????} ??
  • ??
  • }??
  • package test;import com.jacob.activeX.ActiveXComponent; import com.jacob.com.Dispatch;public class TestMail3 {/*** @param args*/public static void main(String[] args) {final int olFolderContacts = 10;ActiveXComponent ol = new ActiveXComponent("Outlook.Application");Dispatch olo = ol.getObject();Dispatch myNamespace = Dispatch.call(olo, "GetNamespace","MAPI").toDispatch();Dispatch myFolder = Dispatch.call(myNamespace, "GetDefaultFolder",new Integer(olFolderContacts)).toDispatch();//n?chste zeile FehlermeldungDispatch items = Dispatch.get(myFolder, "Items").toDispatch();int count = Dispatch.call(items, "Count").toInt();for (int i = 1; i <= count; i++) {Dispatch item;item = Dispatch.call(items, "Item", new Integer(i)).toDispatch();String fullName = Dispatch.get(item, "Fullname").toString();String emailAddress = Dispatch.get(item, "Email1Address").toString();String addressStreet = Dispatch.get(item, "BusinessAddressStreet").toString();String addressCity = Dispatch.get(item, "BusinessAddressCity").toString();String addressCountry = Dispatch.get(item, "BusinessAddressCountry").toString();String addressPostalCode = Dispatch.get(item,"BusinessAddressPostalCode").toString();String addressState = Dispatch.get(item, "BusinessAddressState").toString();String title = Dispatch.get(item, "Title").toString();String phone = Dispatch.get(item, "BusinessTelephoneNumber").toString();String fax = Dispatch.get(item, "BusinessFaxNumber").toString();printField("", fullName);printField("", title);printField("", addressStreet);printField("", addressCity);printField("", addressState);printField("", addressPostalCode);printField("", addressCountry);printField("Tel:", phone);printField("Fax:", fax);printField("Email:", emailAddress);System.out.println();}}public static void printField(String label, String value) {if (value.length() != 0) {System.out.println(label + " " + value);}}}

    ?第二例地址:

    http://www.velocityreviews.com/forums/t147294-java-libray-to-extract-email-contact-only-from-outlook-file.html

    ?

    官網(wǎng)問(wèn)題搜索:

    http://sourceforge.net/projects/jacob-project/forums/forum/375946/topic/3734426/index/page/1

    http://sourceforge.net/search/?group_id=109543&type_of_search=forums&group_forum_id=375946&words=outlook&search=Search

    。。。

    ?

    總結(jié)

    以上是生活随笔為你收集整理的java调用outlook的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。