img img img img img  
Home Development Partners Resellers About  
img   img The Messaging API is a COM-like API that provides access to the contents of messaging stores. "Extended MAPI in Delphi" is a package providing access to Outlook-compatible objects through a COM-based API. Using MAPI, a program can connect to a MAPI store, and then perform operations against that store.
img Extended MAPI in Delphi

Extended MAPI in DELPHI Examples Examples (page 4)

 
 
 
img Request # 8
How to use Personal folder (*.PST) files from DELPHI
(Loading and Creating a *.PST)

How with Extended MAPI a developer working on Borland DELPHI can create or/and load a PST file without existing MAPI profile.
Then you can use this *.PST as your Private Store, that hold secret data.
Personal Information Stores - PST files - offers ideal opportunities for storing our correspondence in one place.

This example will illustrate how to create/open PST files.
In addition, we will illustrate how to copy/move/erase messages and folders.
We chose to illustrate this here, since it is assumed that the PST file will not contain significant information and we may fidget with the data.

We will show you how to implement the IMAPIProgress class that MAPI provides for the process visualization.
With it you may, for instance, build an indicator that will show the process of copying 10 000 e-mails from one folder into another. The user will be able to monitor the process and will not be bored - something is "moving" there :-)

Also:
  •  Using IMsgStore
  •  Using IMsgServiceAdmin
  •  Using IProfAdmin
  • ...


ByRequest08EM  as Compiled Application


Source Code: In package
img Request # 9
How to get access to Exchange Public folders from DELPHI

This example (By Request #9) will show you how to get access to public folders.
This example requires connection with Exchange Server for efficient implementation.

ByRequest09EM  as Compiled Application


Source Code: In package
img Request # 10
Extended MAPI DCOM NT Server as Service

The idea behind this example is to implement a MAPI object that works as a COM Server in Windows NT Service.
Our MAPI COM Server will perform basic things - LogOn, LogOff and will take all the messages from the Inbox folder.

Start up parameters of this NT Service are PROFILENAME and PROFILEPASSWORD.
We will also create a test client enabling us to check how our server works.

Why do we need this example?
For instance, you may create a perfectly normal DCOM client with DELPHI that uses Extended MAPI and is placed on some user's computer. This client may have connection to GAL for instance or to Contacts Folders through our NT Service. This may be for instance the Front Desk girl for whom we need to install an e-mail client or it may be used by the HR department for updating data. This NT Service may also be used by ASP pages through VB scripts.

You can use also for better result SvCom package from ALDYN Software

SvCom is an integrated package of classes and tools for development of service applications and use of NT Security framework. Currently SvCom components work with Delphi 4, 5, 6, 7 and 2005 and C++ Builder 5 and 6 under all flavors of Windows.
...
procedure TMAPIActiveXService.ServiceBeforeInstall(Sender: TService);
begin
ServiceStartName := FindMySwitch('USERNAME', ['-', '/']);
LogMessage(ServiceStartName, 0);
Password := FindMySwitch('USERPASS', ['-', '/']);
end;

procedure TMAPIActiveXService.ServiceAfterInstall(Sender: TService);
begin
try
RegAction := raReg;
RegisterEXE;
RegisterAsService(GUIDToString(CLASS_MAPICOMServer), self.Name);
except
on e: Exception do if e.Message <> '' then
MessageBox(0, PChar(e.Message), 'MAPI ActiveX Service', MB_OK or MB_ICONERROR or MB_SERVICE_NOTIFICATION);
else
MessageBox(0, 'Can not install "MAPI ActiveX Service" service!', 'MAPI ActiveX Service', MB_OK or
MB_ICONERROR or MB_SERVICE_NOTIFICATION);
end;
end;
....

ByRequest10EM  as Compiled Application


Source Code: In package
img Request # 11
Get all available Message Stores in our MAPI Profile


This example (By Request #11) will show you how to get access to all message stores listed in our MAPI profile. This includes also Delegated Mailbox.

This example requires connection with Exchange Server for efficient implementation.

ByRequest11EM  as Compiled Application


Source Code: In package
img
img Request # 12
Exchange ACL (Modifying Access Rights) Public Folders Access Control

Access to Exchange server public folders is protected by custom mechanism. Although an object, which represents a folder in the Directory may have an associated Windows NT security descriptor with DACL in it, client access is controlled by an access control list of another kind. There is a bit of confusion here because both are called ACLs. The difference is that a Windows NT ACL specifies rights for Windows NT accounts, while a public folder ACL deals with MAPI PR_ENTRYIDs. I have a separate topic How NT Access Control Relates to Public Folder ACLs that describes where these two things come together. You can access public folder ACLs via either IExchangeFolderACLs interface, or IExchangeModifyTable. We have written
a few samples that illustrate both approaches. Also, MSDN has a sample named ACLEDIT, which illustrates usage of IExchangeFolderACLs. Access Rights The following code fragment extracted from the Edk.pas file lists documented access rights.

//Security bits
const
frightsReadAny = ULONG($0000001);
frightsCreate = ULONG($0000002);
frightsEditOwned = ULONG($0000008);
frightsDeleteOwned = ULONG($0000010);
frightsEditAny = ULONG($0000020);
frightsDeleteAny = ULONG($0000040);
frightsCreateSubfolder = ULONG($0000080);
frightsOwner = ULONG($0000100);
frightsContact = ULONG($0000200); 
rightsNone = ULONG($00000000);
rightsReadOnly = frightsReadAny;
rightsReadWrite = (frightsReadAny or frightsEditAny);
rightsAll = ULONG($00001FB); The table below explains their meanings:

Flags
Meaning
frightsReadAny A right to read any message in the folder. 
frightsCreate A right to create messages in the folder. 
frightsEditOwned A right to edit any message owned by a user.
frightsDeleteOwned A right to delete any message owned by a user.
frightsEditAny A right to edit any message in the folder.
frightsDeleteAny A right to delete any message in the folder.
frightsCreateSubfolder A right to create a subfolder in the folder.
frightsOwner Indicates that a user owns the folder.
frightsContact Indicates that a user is the contact person for the folder.
rightsNone No rights at all.
rightsReadOnly Same as frightsReadAny.
rightsReadWrite Combines frightsReadAny and frightsEditAny access.
rightsAll All documented rights with exemption of frightsContact.


In addition to these rights Exchange server uses flag $0000400, which determines folder visibility to a user. This flag is not a member of rightsAll.

Roles

Microsoft Exchange server uses a few roles for public folder clients. Roles are convenient combinations of individual access rights. The following roles are defined:

Role
Access Mask
Owner $000007FB
Publishing Editor $000004FB
Editor $0000047B
Publishing Author $0000049B
Author $0000041B
Nonediting Author $00000413
Reviewer $00000401
Contributor $00000402


You may easily determine which individual rights contribute to the role by examining it access mask.

Who May Be Listed in an ACL?

The following entities may be listed in a public folder ACL:
  • A user from Microsoft Exchange server address book.
  • A distribution list from Microsoft Exchange server address book.
  • A public folder.
  • A defined role.
  Using IExchangeModifyTable to Modify Public Foldr Access

img Let us see how IExchangeModifyTable interface may be used to read and modify access control entries for a public folder. The following example application demonstrates reading and modifying access masks.

ByRequest12EM  as Compiled Application


Source Code: In package
img Request # 13
Out Of Office (Auto Replay Message, Message Rule)

This step-by-step article describes how to create an out-of-office
rule with Extended MAPI.

 How to:
  • Turn On Rule
  • Turn Off Rule
  • Modify Message Text
  • Create a new Message Rule


This example requires connection with Exchange
Server for efficient running.

ByRequest13EM  as Compiled Application

Source Code: In package

img
img Request # 14
Outlook Folders (Inbox, Outbox, Sent Items, Deleted Items, Calendar, Contacts, Journal, Notes, etc...)

This example (By Request #14) will show you how to get direct access to Microsoft Outlook specific folders as Calendar, Contacts, Notes, etc..

 Example includes functions as:
  • GetInbox
  • GetOutbox
  • GetSentBox
  • GetTrashBox
  • GetDefaultFolder- direct access to Microsoft Outlook specific folders as Calendar, Contacts, Drafts,  Journal, Notes, Tasks...

ByRequest14EM  as Compiled Application


Source Code: In package
img
img Request # 15
Fast E-mail Agent

Very often we receives a requests for a code by which a few lines written in Delphi can sent e-mail using Microsoft Exchange Server as e-mail server. This example covers exactly that.


procedure TfrmMain.LogonAndSend;
var
 StoreLogoffFlag:Cardinal;
 OutboxEntryID: TSBinary;
 ObjType:Cardinal;
 SentMailEID: PSPropValue;
 TempString:String;
begin
   ZeroMemory(@OutboxEntryID, SizeOf(OutboxEntryID));
   SentMailEID:=nil;

  // Init MAPI Subsystem
  hr:=MAPIInitialize(nil);
  if failed(hr) then raise Exception.Create(GetMAPIError(nil, hr));

  try
  //Establish Session
  hr:=MAPILogonEx(Application.Handle, //Parent Window
                                 nil, //Profile name
                                 nil, //Profile password - newer used
                                 MAPI_EXTENDED or          {/* Extended MAPI Logon */}
                                 MAPI_NEW_SESSION or       {/* Don't use shared session */}
                                 MAPI_SERVICE_UI_ALWAYS  or
                                 MAPI_ALLOW_OTHERS or      {/* Make this a shared session */}
                                 MAPI_LOGON_UI,            {/* Dialog box should be displayed */}
                                 FMAPISession);

   if failed(hr) then
    begin
      FMAPISession:=nil;
      raise Exception.Create(GetMAPIError(nil, hr));
    end;

    // NOT NEED REALLY, BUT I LIKE TO KNOW MAPI VERSION
   StatusBar.SimpleText:='  MAPIVersion:' + GetMAPIVersion;

   //Get interface to Address Book
    hr := FMapiSession.OpenAddressBook(Self.Handle, nil, 0, FAddressBook);
    if failed(hr) then raise Exception.Create(GetMAPIError(FMapiSession, hr));

   //Get interface to Mailbox
    hr := HrOpenExchangePrivateStore(FMapiSession, FMailbox);
    if failed(hr) then raise Exception.Create(GetMAPIError(FMapiSession, hr));

   //Get Entry ID of Outbox folder
    hr := HrMAPIFindOutbox(FMailbox, OutboxEntryID.cb, PEntryID(OutboxEntryID.lpb));
    if failed(hr) then raise Exception.Create(GetMAPIError(FMailbox, hr));

   //Get Interface to Outbox folder
    hr := FMailbox.OpenEntry(OutboxEntryID.cb, PEntryID(OutboxEntryID.lpb), @IID_IMAPIFolder,
      MAPI_MODIFY or MAPI_NO_CACHE,
      ObjType,
      IUnknown(FOutbox));

    if (MAPI_E_UNKNOWN_FLAGS = hr) then // Outlook Version < 2003
    hr := FMailbox.OpenEntry(OutboxEntryID.cb, PEntryID(OutboxEntryID.lpb), @IID_IMAPIFolder,
      MAPI_MODIFY,
      ObjType,
      IUnknown(FOutbox));
    if failed(hr) then raise Exception.Create(GetMAPIError(FMailbox, hr));

    // Get Sent Items Folder - we will move message to this folder after submit
    // not mandatory - see below
    hr := HrGetOneProp(FMailbox, PR_IPM_SENTMAIL_ENTRYID, SentMailEID);
    if failed(hr) then raise Exception.Create(GetMAPIError(FMailbox, hr));
    SentMailEID.ulPropTag := PR_SENTMAIL_ENTRYID;

    // Create a new empty message
    hr := FOutbox.CreateMessage(nil, 0, FMAPIMessage);
    if failed(hr) then raise Exception.Create(GetMAPIError(FOutbox, hr));

    // Set Message Class
    hr:=HrMAPISetPropString(FMAPIMessage, PR_MESSAGE_CLASS, Pointer(PChar('IPM.Note')));
    if failed(hr) then raise Exception.Create(GetMAPIError(FMAPIMessage, hr));

    // Set Sent Items Entry ID - not mandatory
    hr:= HrSetOneProp(FMAPIMessage,SentMailEID);
    if failed(hr) then raise Exception.Create(GetMAPIError(FMAPIMessage, hr));

    // Set Message Subject
    TempString:=Trim(ebSubject.Text);
    if TempString='' then TempString:='Test Message';
    hr:=HrMAPISetPropString(FMAPIMessage, PR_SUBJECT, Pointer(PChar(TempString)));
    if failed(hr) then raise Exception.Create(GetMAPIError(FMAPIMessage, hr));

    // Set Message Body
     TempString:=Trim(BodyMemo.Text);
     if Length(TempString)>254 then
        SetLargeBody
     else if Length(TempString)>0 then
      begin
       hr:=HrMAPISetPropString(FMAPIMessage, PR_BODY, Pointer(PChar(TempString)));
       if failed(hr) then raise Exception.Create(GetMAPIError(FMAPIMessage, hr));
      end;

     //Set Recipients
     Resolve;

     // Save all changes
     hr := FMAPIMessage.SaveChanges(KEEP_OPEN_READWRITE);
     if failed(hr) then raise Exception.Create(GetMAPIError(FMAPIMessage, hr));

     // Send Message
     hr := FMAPIMessage.SubmitMessage(0);
     if failed(hr) then raise Exception.Create(GetMAPIError(FMAPIMessage, hr));

     ShowMessage('The message is going out...');

  finally
    //Clear Sent Item Entry ID
    if Assigned(SentMailEID) then MAPIFreeBuffer(SentMailEID);
    //Clear Outbox EntryID
    if Assigned(OutboxEntryID.lpb) then MAPIFreeBuffer(OutboxEntryID.lpb);
    //Clear Outbox Interface
    FOutbox:=nil;
    //Clear Message Interface
    FMAPIMessage:=nil;

    FAddressBook:=nil;
    if Assigned(FMailbox) then
       begin
         StoreLogoffFlag:=LOGOFF_NO_WAIT;
         FMailbox.StoreLogoff(StoreLogoffFlag);
         FMailbox:=nil;
       end;
    if Assigned(FMAPISession) then
        FMAPISession.Logoff(Application.Handle,
                            MAPI_LOGOFF_UI,
                            0); // always 0
   FMAPISession:=nil;
  end;
  MAPIUnInitialize;
end;


ByRequest15EM  as Compiled Application


Source Code: In package
img Request # 16
DateTime restriction and Appointments

This example shows how to construct DateTime restriction. With this restriction we will limit the listed Appointments to certain time interval.

ByRequest16EM  as Compiled Application


Source Code: In package
img Request # 17
TClientDataSet & Extended MAPI

This example shows how you can use TClientDataSet and Extended MAPI togeter.

ByRequest17EM  as Compiled Application
 

Source Code: In package
TClientDataSet and Extended MAPI
img Request # 18
Signed Extended MAPI messages (digitally signed email)

This example shows how you can decode digitally signed email.

ByRequest18EM  as Compiled Application


Source Code: In package
digitally signed email
img Request # 19
How to resolve display name to e-mail address and bind the Global Address List (GAL) to TClientDataSet/TDataSource/TDBNavigator/etc..

ByRequest19EM  as Compiled Application


Source Code: In package
GAL DB
img Request # 20
How to post/send an item to Microsoft Exchange Public Folder

ByRequest20EM  as Compiled Application

This example shows how you can post/send an item to public folder, how to find and/or create a public folder, etc..



Source Code: In package
How to post/send an item to Microsoft Exchange Public Folder
img Request # 21
How to Send an e-mail message on behalf of someone else

ByRequest21EM as Compiled Application

Send on Behalf will allow a user to send as another user while showing the recipient that it was sent from a specific user on behalf of another user.
How to:
- Displays the Outlook address book dialog box.
- Performs name resolution, assigning entry identifiers to recipients in a recipient list.
- use PR_SENT_REPRESENTING_XXXX properties


Source Code: In package
How to Send an e-mail message on behalf of someone else
img Request # 22
Command line .exe that sends e-mails

ByRequest22EM  as Compiled Application

Parameters:
T -> Recipients TO List
C -> Recipients CC List
S -> Message Subject
B -> Message HTML Body (path to existing html file)
A -> Attachments List (path to existing file)
P –> MAPI/Outlook profile name
U -> User SMTP e-mail address (existing exchange user)

Command line .exe that sends e-mails 
 
  Usage (example):

CmdMail.exe -T="imibo@imibo.com, info@imibo.com, lolo@imibo.com" -P=Outlook -U="SMTP:az00008@mapisoft.com" -S="Test Message" -B="C:\Temp\Questions.htm" -A="C:\TEMP\SmtpClient.zip, C:\TEMP\TestFile.zip"

T -> Recipients TO List – each recipient should be delimited by comma. Value is quoted (“)
C -> Recipients CC List – each recipient should be delimited by comma. Value is quoted (“)
A -> Attachments List (path to existing file) – each attachment should be delimited by comma. Value is quoted (“)
P –> MAPI/Outlook profile name – Name of MAPI profile for connection to Exchange Server. Should be configured as on-line connection (do not use “cache/offline”!) with Exchange Server, administrative rights.
U -> User SMTP e-mail address – from this e-mail address (mailbox), will be sent e-mail.

code (snap):

 program CmdMail;
{$APPTYPE CONSOLE}
{$R *.res}
{$I IMI.INC}
uses Classes, SysUtils, Windows, ActiveX, EDK, MAPIException, MAPIPropUtils, ExtendedMAPI;
const  cRecepientsTo = 'T';  cRecepientsBcc = 'C';  cSubject = 'S';  cBodyPath = 'B';  cAttachementsPath = 'A';  cProfile = 'P';  cUser = 'U';  PropForCorrect : record cValues: ULONG
   aulPropTag :array [0 .. 2] of ULONG;  end = (cValues: 3; aulPropTag: (PR_EMAIL_ADDRESS_A, PR_ADDRTYPE_A, PR_DISPLAY_NAME_A)); var  hr: HRESULT;  IsInitOK: Boolean = False;  MAPIProfile: AnsiString = '';  MAPISession: IMAPISession = nil;  AddressBook: IAddrBook = nil; GAL: IABContainer = nil; ExchPrivateStore: IMsgStore = nil; ExServer: AnsiString = ''; UserPrivateStore: IMsgStore = nil; UserEMailAddress: AnsiString = ''; ServerDN: AnsiString = ''; MailboxDN: AnsiString = ''; Outbox: IMAPIFolder = nil; // ------------------------------ // procedure... procedure... procedure...
procedure GetInputMAPIParams; var I: Integer; S: AnsiString; begin for I := 1 to ParamCount do begin S := AnsiString(ParamStr(I)); if (Copy(S, 1, 1) = '-') or (Copy(S, 1, 1) = '/') then begin if CompareText(Copy(String(S), 2, 1), cProfile) = 0 then begin MAPIProfile := Copy(S, 4, Length(S)); MAPIProfile := AnsiString(StringReplace(String(MAPIProfile), '"', '', [rfReplaceAll])); end else if CompareText(Copy(String(S), 2, 1), cUser) = 0 then begin UserEMailAddress := Copy(S, 4, Length(S)); UserEMailAddress := AnsiString(StringReplace(String(UserEMailAddress), '"', '', [rfReplaceAll])); end end; end; end; // ------------------------------ // begin try try // Init MAPI Subsystem if InitMAPI then begin Writeln('GetInputMAPIParams -> Done!'); GetInputMAPIParams; //Establish Session if LogonToMapi then begin Writeln('LogonToMapi -> Done!'); // Load your OWN Mailbox (Administrative mailbox) LoadPrivateMDB; Writeln('LoadPrivateMDB -> Done!'); // Open Address Book; LoadAddressBook; Writeln('LoadAddressBook -> Done!'); // Resolve Other user ResolveEmlAddr; Writeln('Resolve Other user -> Done!'); // Open Other User Mailbox OpenOtherUsersMailbox; Writeln('Open Other Users Mailbox -> Done!'); // Get Outbox GetOutbox; Writeln('Get Outbox -> Done!'); // Process Params ProcessParams; Writeln(''); Writeln('Send Message -> Done! Press any key to exit!'); Readln; end; end; except on E: Exception do begin Writeln(E.ClassName, ': ', E.Message); Writeln('Press any key to exit!'); Readln; end; end; finally if IsInitOK then MAPIClose; end; end.

Source Code: In package
img Request # 23
How to get and show the contact phones?

ByRequest23EM  as Compiled Application

This example shows how you can get most of contact phones as:
PR_ASSISTANT_TELEPHONE_NUMBER
PR_BEEPER_TELEPHONE_NUMBER
PR_BUSINESS_TELEPHONE_NUMBER
PR_BUSINESS_FAX_NUMBER
etc..

Source Code: In package
How to get and show most of contact phones
img Request # 24
How to build an address book dialog (Delphi way)?

ByRequest24EM  as Compiled Application

Source Code: In package
How to build an address book dialog (Delphi way)?
img Request # 25
How to Open another person's Calendar folder and post an Appointment item?


This example requires you to use a Microsoft Exchange account.
The ability to open another person's folder, and whether or not you can change it, is controlled by the owner of the folder.


ByRequest25EM  as Compiled Application

Source Code: In package
Appointment item
Appointment item Main Screen
img Request # 26
How to Open another person's Task folder and post a Task item?


This example requires you to use a Microsoft Exchange account.
The ability to open another person's folder, and whether or not you can change it, is controlled by the owner of the folder.


ByRequest26EM  as Compiled Application

Source Code: In package
Task item
Task item Main Screen
img Request # 27
How to Open another person's Contact folder and post a Contact item?


This example requires you to use a Microsoft Exchange account.
The ability to open another person's folder, and whether or not you can change it, is controlled by the owner of the folder.


ByRequest27EM  as Compiled Application

Source Code: In package
Contact item
Contact item Main Screen
img Request # 28
How to Save (store) Meetings/Appointments item to DataBase and synchronize them (one way)?


This example requires you to use a Microsoft Exchange account.


ByRequest28EM  as Compiled Application

Source Code: In package
item
Main Screen
img Request # 29
How to spy for incoming messages where Subject contains "xxxxx" and move them to specific folder?


This example requires you to use a Microsoft Exchange account.


ByRequest29EM  as Compiled Application

Source Code: In package
item
  continue...
img The Next Extended MAPI in Delphi Examples
Copyright © 2017 IMIBO
Privacy Statement