8

我想在 Outlook 中创建一个带有附件的邮件并在发送之前显示它,但我想我已经尝试了我在网上找到的几乎所有样本,但没有任何运气。我可以使用 Indy,但我非常想使用 Outlook 来确保邮件是正确的,因为它是用于商业用途的。

将地址、主题、消息和附件作为参数的函数的任何输入,然后在发送前在 Outlook 中显示消息。

4

1 回答 1

15

请参阅MailItem.Display 方法

uses
  comobj;

..

procedure DisplayMail(Address, Subject, Body: string; Attachment: TFileName);
var
  Outlook: OleVariant;
  Mail: Variant;
const
  olMailItem = $00000000;
begin
  try
    Outlook := GetActiveOleObject('Outlook.Application');
  except
    Outlook := CreateOleObject('Outlook.Application');
  end;
  Mail := Outlook.CreateItem(olMailItem);
  Mail.To := Address;
  Mail.Subject := Subject;
  Mail.Body := Body;
  if Attachment <> '' then
    Mail.Attachments.Add(Attachment);
  Mail.Display;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DisplayMail('mailaddress', 'subject', 'message', 'attachmentfile');
end;
于 2011-12-11T12:43:53.383 回答