【问题标题】:How is working with Outlook in Delphi different than other email clients?在 Delphi 中使用 Outlook 与其他电子邮件客户端有何不同?
【发布时间】:2011-10-20 00:48:19
【问题描述】:

我在我的 Delphi 应用程序中创建了一条 mapi 消息,然后用户只需在他们的默认 mapi 电子邮件客户端中发送该消息,即格式化的消息出现在他们的邮件客户端中,然后他们点击“发送”。

当电子邮件客户端是 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;

【问题讨论】:

  • 请向我们展示您的代码。同时你可以看看here。在 Delphi 中如何使用 MAPI 有很多复杂的例子。
  • 感谢 TLama。我正在使用 Mike Shkolnik 的 MapiMail 组件 (www.scalabium.com)。无论问题是什么,似乎只有 Outlook (2007) 受到影响。

标签: delphi outlook-2007


【解决方案1】:

Outlook 使用 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('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;

【讨论】:

  • 谢谢。使用 MailInspector 是显示消息的方式。在 Delphi 函数结束后使用 MailItem.Display(true) 导致“无效函数”异常。
猜你喜欢
  • 2012-05-09
  • 2018-12-02
  • 1970-01-01
  • 1970-01-01
  • 2010-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多