2011-10-20 41 views
1

我在Delphi應用程序中創建了mapi消息,然後用戶只需在默認的mapi電子郵件客戶端中發送消息,即格式化的消息出現在他們的郵件客戶端中,然後他們單擊「發送」。如何在Delphi中使用Outlook與其他電子郵件客戶端不同?

當電子郵件客戶端是Thunderbird或Outlook Express時,一切正常,但Outlook(2007)中的內容很陌生。例如,重點放在Outlook上,但用戶無法關閉Outlook窗口,有時用戶甚至無法在程序中使用鼠標 - 箭頭在Outlook中消失。我發現自己必須從任務管理器關閉應用程序。

從我的新手角度來看,這個問題是控制形式和焦點之一,而不僅僅是連接到簡單或擴展的mapi;後者在這種情況下似乎不相關。

有人知道這裏發生了什麼嗎?我該如何改變我的代碼來處理這個問題?

這是代碼:

MapiMail1 := TMapiMail.Create(self); 
try 
    MapiMail1.Recipients.Add(MainGrid.AllCells[aCol, aRow]); 
    MapiMail1.Subject := ''; 
    MapiMail1.Body := ''; 
    MapiMail1.EditDialog := True; 
    MapiMail1.Send; 
finally 
    MapiMail1.Free; 
end; 
+0

請告訴我們您的代碼。同時你可以看看[這裏](http://www.imibo.com/imidev/delphi/les/index.html)。在Delphi中有很多複雜的例子如何使用MAPI。 – TLama

+0

謝謝TLama。我使用Mike Shkolnik的MapiMail組件(www.scalabium.com)。無論問題是什麼,看起來只是Outlook(2007)受到影響。 –

回答

3

觀的偉大工程,使用OLE,而不是MAPI。試試這個:

USES OleCtrls, ComObj; 

procedure TForm1.Button1Click(Sender: TObject); 
const 
    olMailItem = 0; 
var 
    Outlook: OLEVariant; 
    MailItem: Variant; 
    MailInspector : Variant; 
    stringlist : TStringList; 
begin 
    try 
    Outlook:=GetActiveOleObject('Outlook.Application') ; 
    except 
    Outlook:=CreateOleObject('Outlook.Application') ; 
    end; 
    try 
    Stringlist := TStringList.Create; 
    MailItem := Outlook.CreateItem(olMailItem) ; 
    MailItem.Subject := 'subject here'; 
    MailItem.Recipients.Add('[email protected]'); 
    MailItem.Attachments.Add('c:\boot.ini'); 
    Stringlist := TStringList.Create; 
    StringList.Add('body here'); 
    MailItem.Body := StringList.text; 
    MailInspector := MailItem.GetInspector; 
    MailInspector.display(true); //true means modal 
    finally 
    Outlook := Unassigned; 
    StringList.Free; 
    end; 
end; 
+1

謝謝你。使用MailInspector是顯示消息的方式。在Delphi函數結束後,使用MailItem.Display(true)會導致「無效函數」異常。 –

相關問題