2011-05-18 69 views

回答

4

如果要在Java中實現電子郵件功能,請考慮JavaMail。另外,如果您的應用程序具有電子郵件功能,那麼您無需打開另一個電子郵件客戶端(如Outlook)。

+0

這是確定一個服務器端應用程序或桌面上的一些特定的使用情況,但總的來說,你需要SMTP服務器發送電子郵件。沒有多少用戶(統計上,沒有人)在本地計算機上運行它。您可以使用遠程SMTP服務器,但即使您構建了繞過防火牆和其他障礙的所有支持,也不希望這樣做,因爲垃圾郵件發送者會將其作爲簡單的午餐吃掉。 – 2014-08-15 05:08:36

+1

@ serg.nechaev你需要一個郵件服務器(SMTP,Exchange,Domino,無論如何)發送郵件:) – MarcoS 2014-08-26 12:25:36

+1

是的,這是一個好點。 – 2014-12-04 05:26:34

8

根據these docs你需要的命令是

"path/to/Outlook.exe /c ipm.note /a \"path/to/attachment\"" 

組裝這一點,並通過ProcessBuilder

運行(或者聽馬科斯誰給的,爲什麼它有時最好不要從字面上回答一個很好的例子問題:-))

5

您可以使用desktop類打開系統的電子郵件客戶端。

Desktop.getDesktop().mail(new URI("mailto:[email protected]")) 
+2

是的,但沒有附件 – 2011-05-18 13:59:48

+0

啊是的,足夠的真實 – OpenSauce 2011-05-18 14:36:16

2

我已經能夠用HTML電子郵件打開MS Outlook 2007。我已經使用SWT OLE API完成了這項工作。這裏是關於Vogela的教程:http://www.vogella.com/articles/EclipseMicrosoftIntegration/article.html

它在教程中說它也適用於非RCP Java。

public void sendEMail() 
{ 

    OleFrame frame = new OleFrame(getShell(), SWT.NONE); 

    // This should start outlook if it is not running yet 
    OleClientSite site = new OleClientSite(frame, SWT.NONE, "OVCtl.OVCtl"); 
    site.doVerb(OLE.OLEIVERB_INPLACEACTIVATE); 

    // Now get the outlook application 
    OleClientSite site2 = new OleClientSite(frame, SWT.NONE, "Outlook.Application"); 
    OleAutomation outlook = new OleAutomation(site2); 

    OleAutomation mail = invoke(outlook, "CreateItem", 0 /* Mail item */).getAutomation(); 

    setProperty(mail, "BodyFormat", 2 /* HTML */); 
    setProperty(mail, "Subject", subject); 
    setProperty(mail, "HtmlBody", content); 

    if (null != attachmentPaths) 
    { 
     for (String attachmentPath : attachmentPaths) 
     { 
      File file = new File(attachmentPath); 
      if (file.exists()) 
      { 
       OleAutomation attachments = getProperty(mail, "Attachments"); 
       invoke(attachments, "Add", attachmentPath); 
      } 
     } 
    } 

    invoke(mail, "Display" /* or "Send" */); 

} 
+0

這種回答對社區更有用,當你提供文章的exerpt,除了鏈接。在將來的某個時候,該鏈接可能無法正常工作 - 並且找到答案的人會再次被卡住。 – 2012-11-29 21:58:13

2

這裏是你想要的確切命令: -

new ProcessBuilder("C:\\Program Files\\Microsoft Office\\Office14\\OUTLOOK.exe","/a","C:\\Desktop\\stackoverflow.txt").start(); 

第一個參數,路徑到Outlook。

Second Argument- Outlook attachment command。

三Argument-附件路徑

相關問題