Available functions:
function GetMsgReadReceiptRequest
function GetMsgDeliveryReportRequest
function GetMsgAttDataAsStream
function SetMsgReadReceiptRequest
function SetMsgDeliveryReportRequest
procedure GetMsgAfterSendAction
procedure SetMsgAfterSendAction
procedure ShowHTMLBodyRendered
function GetMsgSenderName(const MAPIMessage: IMessage): String;
description
Returns the message sender's display name (PR_SENDER_NAME)
parameters
MAPIMessage - IMessage.
usage
// Get From Name
labelFrom.Caption := GetMsgSenderName(FMAPIMessage);
function GetMsgSenderAddress(const MAPIMessage: IMessage): String;
description
Returns the message sender's E-mail address (PR_SENDER_EMAIL_ADDRESS)
parameters
MAPIMessage - IMessage.
usage
// Get From Name
labelFrom.Caption := GetMsgSenderName(FMAPIMessage);
// Get From Address
labelFrom.Caption := labelFrom.Caption + ' [' +
GetMsgSenderAddress(FMAPIMessage) + ']';
function GetMsgToNames(const MAPIMessage: IMessage): String;
description
Returns a list of the display names of the primary (To) message recipients,
separated by semicolons (;). (PR_DISPLAY_TO)
parameters
MAPIMessage - IMessage.
usage
// Get From Name
labelFrom.Caption := GetMsgSenderName(FMAPIMessage);
// Get From Address
labelFrom.Caption := labelFrom.Caption + ' [' +
GetMsgSenderAddress(FMAPIMessage) + ']';
// To
lbTo.Caption := GetMsgToNames(FMAPIMessage);
function GetMsgCcNames(const MAPIMessage: IMessage): String;
description
Returns an ASCII list of the display names of any carbon copy (CC) message
recipients, separated by semicolons (;). (PR_DISPLAY_CC)
parameters
MAPIMessage - IMessage.
usage
// Get From Name
labelFrom.Caption := GetMsgSenderName(FMAPIMessage);
// Get From Address
labelFrom.Caption := labelFrom.Caption + ' [' +
GetMsgSenderAddress(FMAPIMessage) + ']';
// To
lbTo.Caption := GetMsgToNames(FMAPIMessage);
// CC
lbCc.Caption := GetMsgCcNames(FMAPIMessage);
function GetMsgRecipients(const MAPIMessage: IMessage; var Recipients: TRecipientsHeadList): Boolean;
description
On Success returns an array of the message recipients header record
parameters
MAPIMessage - IMessage.
Recipients - TRecipientsHeadList
Array of Recipient header records
usage
// Get saved (existing) recipients
GetMsgRecipients(FMAPIMessage, RecipientHeadList);
FillEmailFields;
procedure FillEmailFields;
var
iCount: Integer;
begin
ebTo.Text := ''; // eb => TEdit
ebCC.Text := '';
ebBcc.Text := '';
for iCount := 0 to Length(RecipientHeadList)
- 1 do
begin
case
RecipientHeadList[iCount].RecipientType of
rtTo:
ebTo.Text := ebTo.Text + RecipientHeadList[iCount].DisplayName + '; ';
rtCc:
ebCC.Text := ebCC.Text + RecipientHeadList[iCount].DisplayName + '; ';
rtBCc:
ebBcc.Text := ebBcc.Text + RecipientHeadList[iCount].DisplayName + '; ';
end;
end;
end;
function GetMsgSubject(const MAPIMessage: IMessage): String;
description
Returns the full subject of a message (PR_SUBJECT)
parameters
MAPIMessage - IMessage.
usage
// Get Subject
labelSubject.Caption := GetMsgSubject(FMAPIMessage);
function GetMsgSentTime(const MAPIMessage: IMessage): TDateTime;
description
Returns the date and time when the message sender submitted a message
parameters
MAPIMessage - IMessage.
usage
// Get Sent time
labelSent.Caption := 'Sent: ' + DateTimetoStr(GetMsgSentTime(FMAPIMessage));
function GetMsgSize(const MAPIMessage: IMessage): ULONG;
description
Returns the sum, in bytes, of the sizes of all properties on a message object
parameters
MAPIMessage - IMessage.
usage
// Get Message Size
labelSize.Caption := 'Msg size: ' + IntToStr(GetMsgSize(FMAPIMessage)) + '
bytes';
function GetMsgHasAttachment(const MAPIMessage: IMessage): Boolean;
description
Returns TRUE if a message contains at least one attachment
parameters
MAPIMessage - IMessage.
usage
// Has Attachment
labelHasAttachment.Caption := 'Has Attachment: ' + BoolTostr(GetMsgHasAttachment(FMAPIMessage),
True);
function GetMsgBodyPlain(const MAPIMessage: IMessage; out Stream: TStream; out Unicode: Boolean; out CodePage: Cardinal): Boolean;
description
Returns the message text
parameters
MAPIMessage - IMessage.
usage
// get plain body
if GetMsgBodyPlain(FMAPIMessage,
Stream, IsUnicode, CodePage) then
begin
if IsUnicode then
Memo.Lines.LoadFromStream(Stream
{$IFDEF DELPHI2009}, TEncoding.Unicode
{$ENDIF})
else
Memo.Lines.LoadFromStream(Stream
{$IFDEF DELPHI2009}, TEncoding.Ascii
{$ENDIF})
end;
function GetMsgBodyRTF(const MAPIMessage: IMessage; out Stream: TStream): Boolean;
description
Returns the Rich Text Format (RTF) version of the message text
parameters
MAPIMessage - IMessage.
usage
// get RTF body
if GetMsgBodyRTF(FMAPIMessage, Stream) then
RichEdit.Lines.LoadFromStream(Stream {$IFDEF DELPHI2009}, TEncoding.Ascii
{$ENDIF});
function GetMsgBodyHTML(const MAPIMessage: IMessage; out Stream: TStream): Boolean;
description
Returns the message body text in HTML format
parameters
MAPIMessage - IMessage.
usage
// get HTML body
procedure GetHTMLBodyRendered;
var
Stream: TStream;
StrStream: TStream;
CodePage: ULONG;
begin
Stream := nil;
try
WebBrowser.Visible := True;
if
GetMsgBodyHTML(FMAPIMessage, Stream) then
begin
CodePage :=
GetMsgInetCodePage(FMAPIMessage);
{$IFDEF DELPHI2009}
StrStream :=
TStringStream.Create('', TEncoding.GetEncoding(CodePage));
{$ELSE}
StrStream :=
TIMIBStringStream.Create('', CodePage);
{$ENDIF}
try
TMemoryStream(Stream).SaveToStream(StrStream);
StrStream.Position := 0;
InitializeCIDMIMEHandler(FMAPIMessage);
{$IFDEF DELPHI2009}
LoadDocFromString(WebBrowser, TStringStream(StrStream).DataString, CodePage);
{$ELSE}
LoadDocFromString(WebBrowser, TIMIBStringStream(StrStream).DataStringW, CodePage);
{$ENDIF}
FreeCIDMIMEHandler;
finally
FreeAndNil(StrStream);
end;
end;
finally
if Assigned(Stream) then
FreeAndNil(Stream);
end;
end;
function GetMsgInetCodePage(const MAPIMessage: IMessage): ULONG;
description
Returns the code page used for message body
parameters
MAPIMessage - IMessage.
usage
// Get Internet Code Page
var
CodePage: ULONG;
lpCPInfoEx: TCPInfoEx;
begin
CodePage := GetMsgInetCodePage(FMAPIMessage);
if GetCPInfoEx(CodePage, 0, lpCPInfoEx) then
labelCodePage.Caption := lpCPInfoEx.CodePageName
else
labelCodePage.Caption := IntToStr(CodePage);
function GetMsgLocaleID(const MAPIMessage: IMessage): ULONG;
description
Returns the Windows LCID of the end user who created this message
parameters
MAPIMessage - IMessage.
function GetMsgImportance(const MAPIMessage: IMessage): TMsgImportance;
description
Returns a value that indicates the message sender's opinion of the importance
of a message
parameters
MAPIMessage - IMessage.
function GetMsgReadReceiptRequest(const MAPIMessage: IMessage): Boolean;
description
Returns TRUE if a message sender wants the messaging system to generate a
read report when the recipient has read a message
parameters
MAPIMessage - IMessage.
function GetMsgDeliveryReportRequest(const MAPIMessage: IMessage): Boolean;
description
Returns TRUE if a message sender requests a delivery report for a particular
recipient from the messaging system before the message is placed in the message
store.
parameters
MAPIMessage - IMessage.
function GetMsgAttTable(const MAPIMessage: IMessage): IMAPITable;
description
Returns the message's attachment table.
parameters
MAPIMessage - IMessage.
function GetMsgAttCount(const MAPIMessage: IMessage): ULONG;
description
Returns the total number of attachments.
parameters
MAPIMessage - IMessage.
function GetMsgAttList(const MAPIMessage: IMessage): TAttHeadList;
description
Returns an array of the message attachments
header record
parameters
MAPIMessage - IMessage.
function GetMsgAttachment(const MAPIMessage: IMessage; const ID: Cardinal; const Modify: Boolean = False): IAttach;
description
Opens an attachment
parameters
MAPIMessage - IMessage.
ID - Attachment unique ID
Modify - requests read/write access
function GetMsgAttDataAsStream(const MAPIMessage: IMessage; const ID: Cardinal; Stream: TStream): Boolean;
description
Opens an attachment and returns a stream with attachment content
parameters
MAPIMessage - IMessage.
ID - Attachment unique ID
Stream - attachment content as Stream
usage
procedure TAttachmentDlg.btSaveAsClick(Sender: TObject);
var
FileName: string;
ID: Cardinal;
index: Integer;
Stream: TMemoryStream;
begin
if not Assigned(AttachmentListView.Selected)
then
Exit;
Index := AttachmentListView.Selected.Index;
ID := FAttHeadList[Index].ID;
FileName := FAttHeadList[Index].FileName;
Stream := TMemoryStream.Create;
try
if not GetMsgAttDataAsStream(FMAPIMessage,
ID, Stream) then Exit;
if not
PromptForFileName(FileName, '', '', '', '', True) then Exit;
Stream.SaveToFile(FileName);
ShowMessage('The Attachment is saved
to "' + FileName + '"');
finally
if Assigned(Stream)
then
FreeAndNil(Stream);
end;
end;
function GetAttDataAsStream(const Attachment: IAttach; Stream: TStream): Boolean;
description
Returns a stream with attachment content
parameters
Attachment - IAttach.
Stream - attachment content as Stream
function SetMsgRecipients(const
MAPIMessage: IMessage; const AddressBook: IAddrBook; var Recipients:
TRecipientsHeadList; UIParam:
ULONG_PTR = 0): Boolean;
description
Set the message recipients
parameters
MAPIMessage - IMessage;
AddressBook - IAddrBook
Recipients - TRecipientsHeadList
- array of Recipients Head Records
UIParam - Specifies the parent window handle
function AddMsgAttachment(const
MAPIMessage: IMessage; Stream: TStream; const DisplayName: string; out
AttachmentNum: Cardinal): IAttach; overload;
description
Create a new attachment from stream
function AddMsgAttachment(const MAPIMessage:
IMessage; const
FileName: string; out AttachmentNum: Cardinal): IAttach; overload;
description
Create a new attachment from file
parameters
MAPIMessage -IMessage
Stream - TStream. Stream which contains attachment content
DisplayName - string. The display name of the attachment
FileName - string. The path and file name of the file containing the data for
the attachment
AttachmentNum - Cardinal. Attachment Unique ID
function SetMsgImportance(const MAPIMessage: IMessage; Importance: TMsgImportance): Boolean;
description
Set message importance (PR_IMPORTANCE)
parameters
MAPIMessage -IMessage
Importance - TMsgImportance
function SetMsgSubject(const MAPIMessage: IMessage; const Subject: string): Boolean;
description
Set message Subject (PR_SUBJECT). The subject properties are typically small
strings of fewer than 256 characters
parameters
MAPIMessage -IMessage
Subject - string
usage
// Set Subject
if Length(Trim(ebSubject.Text)) > 0 then
SetMsgSubject(FMAPIMessage, Trim(ebSubject.Text));
// set Importance
SetMsgImportance(FMAPIMessage, TMsgImportance(rgMsgImportance.ItemIndex));
// set Read Receipt Request
SetMsgReadReceiptRequest(FMAPIMessage, cbReadRequest.Checked);
// Delivery ReportRequest
SetMsgDeliveryReportRequest(FMAPIMessage, cbDelivery.Checked);
function SetMsgReadReceiptRequest(const MAPIMessage: IMessage; const Request: Boolean): Boolean;
description
Set message Read Receipt Request (PR_READ_RECEIPT_REQUESTED). Set Request to
TRUE if a message sender wants the messaging system to generate a read report
when the recipient has read a message.
parameters
MAPIMessage -IMessage
Request - Boolean
usage
// Set Subject
if Length(Trim(ebSubject.Text)) > 0 then
SetMsgSubject(FMAPIMessage, Trim(ebSubject.Text));
// set Importance
SetMsgImportance(FMAPIMessage, TMsgImportance(rgMsgImportance.ItemIndex));
// set Read Receipt Request
SetMsgReadReceiptRequest(FMAPIMessage, cbReadRequest.Checked);
// Delivery ReportRequest
SetMsgDeliveryReportRequest(FMAPIMessage, cbDelivery.Checked);
function SetMsgDeliveryReportRequest(const MAPIMessage: IMessage; const Request: Boolean): Boolean;
description
Set message Delivery Report Request (PR_ORIGINATOR_DELIVERY_REPORT_REQUESTED).
Set Request to TRUE if a message sender requests a delivery report for a
particular recipient from the messaging system before the message is placed in
the message store.
parameters
MAPIMessage -IMessage
Request - Boolean
usage
// Set Subject
if Length(Trim(ebSubject.Text)) > 0 then
SetMsgSubject(FMAPIMessage, Trim(ebSubject.Text));
// set Importance
SetMsgImportance(FMAPIMessage, TMsgImportance(rgMsgImportance.ItemIndex));
// set Read Receipt Request
SetMsgReadReceiptRequest(FMAPIMessage, cbReadRequest.Checked);
// Delivery ReportRequest
SetMsgDeliveryReportRequest(FMAPIMessage, cbDelivery.Checked);
function SetMsgLocaleID(const MAPIMessage: IMessage; const LocaleID: Cardinal): Boolean;
description
Set Windows LCID of the end user who created this message (PR_MESSAGE_LOCALE_ID)
parameters
MAPIMessage -IMessage
LocaleID - Cardinal
procedure ClearMsgBodyPart(const MAPIMessage: IMessage);
description
Deletes all body parts as Plain, RTF, HTML. Do not call it when Message Store
reside inside Exchange Server.
parameters
MAPIMessage -IMessage
function SetMsgBodyPlain(Const MAPIMessage: IMessage; Stream: TStream): Boolean;
description
Set the message plain text body (PR_BODY). The value for Stream must be
expressed in the code page of the operating system that MAPI is running on.
parameters
MAPIMessage -IMessage
Stream - TStream. Text body.
usage
Stream := TMemoryStream.Create;
try
Memo.Lines.SaveToStream(Stream {$IFDEF
DELPHI2009}, TEncoding.Unicode {$ENDIF});
if Stream.Size > 0 then
SetMsgBodyPlain(FMAPIMessage,
Stream);
finally
FreeAndNil(Stream);
end;
function SetMsgBodyRtf(Const MAPIMessage: IMessage; Stream: TStream): Boolean;
description
Set the message plain RTF body (PR_RTF_COMPRESSED). RTF is always ASCII.
parameters
MAPIMessage -IMessage
Stream - TStream. RTF uncompressed stream.
usage
Stream := TMemoryStream.Create;
try
// RTF is always ASCII
RichEdit.Lines.SaveToStream(Stream
{$IFDEF DELPHI2009}, TEncoding.Ascii {$ENDIF});
if Stream.Size > 0 then
SetMsgBodyRTF(FMAPIMessage, Stream);
finally
FreeAndNil(Stream);
end;
function SetMsgBodyHtml(Const MAPIMessage: IMessage; Stream: TStream): Boolean;
description
Set the message HTML text (PR_HTML).
parameters
MAPIMessage -IMessage
Stream - TStream. HTML stream.
usage
Stream := TMemoryStream.Create;
try
SaveDocToStream(WebBrowser, Stream); //
MAPIBestBody.pas; WebBrowser - TWebBrowser
NormalizeHTMLStream(Stream); // if
Stream is <> from ASCII, convert it to UTF-8
if Stream.Size > 0 then
SetMsgBodyHtml(FMAPIMessage,
Stream);
finally
FreeAndNil(Stream);
end;
function SaveMsg(Const MAPIMessage: IMessage): Boolean;
description
Makes permanent any changes that were made to a message
parameters
MAPIMessage -IMessageTop
procedure SubmitMsg(Const MAPIMessage: IMessage);
description
Saves all of the message's properties and marks the message as ready to be sent
parameters
MAPIMessage -IMessage
procedure DeleteMsgAttachment(const MAPIMessage: IMessage; const AttachmentID: Cardinal; const Permanent: Boolean = False);
description
Deletes an Attachment
parameters
MAPIMessage -IMessage
AttachmentID - Unique attachment ID
Permanent - A deleted attachment is not permanently deleted if Permanent
is False. In case of Permanent = False
you need to call function
SaveMsg after that.
procedure DeleteMsg(const MAPIMessage: IMessage; const OwnerFolder: IMAPIFolder);
description
Deletes message from the current folder
parameters
MAPIMessage -IMessage
OwnerFolder - IMAPIFolder
procedure GetMsgAfterSendAction(const MAPIMessage: IMessage; out MoveToSentItems: Boolean; out Delete: Boolean);
description
Get information how to be processed a Sent Message
parameters
MAPIMessage -IMessage
MoveToSentItems - Boolean. If TRUE, moves the message to the Sent Items folder.
Delete - Boolean. If TRUE, deletes the message
The following table describes how these values affect what you do with sent messages.
| If neither property is set: | Leave the message in the folder from which it was sent (typically the Outbox). |
| MoveToSentItems is TRUE | Move the message to the Sent Items folder |
| Delete is TRUE | Delete the message |
procedure SetMsgAfterSendAction(const DefaultMsgStore: IMsgStore; const MAPIMessage: IMessage; const MoveToSentItems: Boolean = True);
description
Set information how to be processed a Sent Message
parameters
DefaultMsgStore - Default for this MAPI session IMsgStore
MAPIMessage -IMessage
MoveToSentItems - Boolean. If TRUE, moves the message to the Sent Items folder.
Delete - Boolean. If TRUE, deletes the message
The following table describes how these values affect what you do with sent messages.
| If neither property is set: | Leave the message in the folder from which it was sent (typically the Outbox). |
| MoveToSentItems is TRUE | Move the message to the Sent Items folder |
| Delete is TRUE | Delete the message |
procedure ShowHTMLBodyRendered(const MAPIMessage: IMessage; const WebBrowser: TWebBrowser);
description
Show HTML Body in TWebBrowser
parameters
MAPIMessage -IMessage
WebBrowser - TWebBrowser
usage
ShowHTMLBodyRendered(FMAPIMessage, WebBrowser);
Copyright © 2012 IMIBO Privacy Statement |