Delphi - Adding BCC & CC Recipients to OLE Outlook object

China☆狼群 提交于 2019-12-08 05:17:09

问题


The answer to the post " How is working with Outlook in Delphi different than other email clients? works great. See below.

Using this example how would you go about adding CC and BCC recipients?

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;

回答1:


The 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 constants: olBCC, olCC, olOriginator, or olTo. The default Type for a new mail recipient is olTo.

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

You may find the How To: Fill TO,CC and BCC fields in Outlook programmatically article helpful.



来源:https://stackoverflow.com/questions/29947771/delphi-adding-bcc-cc-recipients-to-ole-outlook-object

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