Delphi - 将 BCC 和 CC 收件人添加到 OLE Outlook 对象

Delphi - Adding BCC & CC Recipients to OLE Outlook object

post 的答案” How is working with Outlook in Delphi different than other email clients? 效果很好。见下文。

使用此示例,您将如何添加 CC 和 BCC 收件人?

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;

Add() method of the Recipients collection creates and returns a new Recipient object. The Type property of the Recipient class allows to set an integer representing the type of recipient. For MailItem recipients, it can be one of the following OlMailRecipientType 常量:olBCColCColOriginatorolTo。新邮件收件人的默认 TypeolTo

MailItem.Recipients.Add('someone@yahoo.com'); // Type=1 olTo
MailItem.Recipients.Add('joesmoe@yahoo.com').Type := 2; // olCC
MailItem.Recipients.Add('alice@yahoo.com').Type := 3; // olBCC

您可能会发现 How To: Fill TO,CC and BCC fields in Outlook programmatically 文章很有帮助。