Create mail with attachment in Outlook and display it

I want to create mail with the application in Outlook and display it before sending, but I think that I tried almost every sample that I found on the network, with no luck. I could use Indy, but I would very much like to use Outlook to be sure that the mail is correct, because it is intended for use in business.

Any input for a function that takes an address, subject, message, and attachment as parameters, and then displays the message in Outlook before sending it.

+7
source share
1 answer

See the MailItem.Display Method .

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; 
+14
source

All Articles