How is working with Outlook in Delphi different than other email clients?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 23:52:35

问题


I create a mapi message in my Delphi app, and users then simply send the message in their default mapi email client, i.e. the formatted message appears in their mail client and they click "send."

Everything works great when the email client is Thunderbird or Outlook Express, but things are stranger when it's Outlook (2007). The focus goes to Outlook, for example, but a user can't close the Outlook window, sometimes the user can't even use a mouse within the program--the arrow disappears within Outlook. I find myself having to close the app from Task Manager.

From my newbie perspective, the issue is one of controlling forms and focus more than something connected to simple or extended mapi; the latter seems irrelevant in this case.

Does anyone know what's going on here? And how I should change my code to deal with the issue?

This is the code:

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;

回答1:


Outlook works great using OLE rather than MAPI. Try this:

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('someone@yahoo.com');
    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;


来源:https://stackoverflow.com/questions/7829915/how-is-working-with-outlook-in-delphi-different-than-other-email-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!