Solved

Exchange Server from D3

Posted on 1998-06-13
12
211 Views
Last Modified: 2010-04-04
Points for example code for creating and deleting Mailboxes on the exchange server.  I am using exchange server v4 sp5.

What I'd like are two functions...

CreateMailbox(UserName, FirstName, LastName, Server, Domain: String);

and

DeleteMailbox(UserName, Server, Domain: String);
0
Comment
Question by:dvaline
  • 3
  • 3
  • 2
  • +2
12 Comments
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
Hi dvaline,

I think it's only possible with the extended MAPI functions, but I never used these... I'll try to look it up but now you have a deriction to look at, yourself.

Regards, Zif.
0
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
0
 
LVL 1

Author Comment

by:dvaline
Comment Utility
Your answer is good, all I need is an example of how to Create a Mailbox and the points are yours, notice, I included a bonus...
0
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
I don't have the slightest idea how to do this but you can EMail the author and ask him for example:
ikojuharov@bitex.com
0
 
LVL 5

Expert Comment

by:ronit051397
Comment Utility
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
I believe this is the article :

In the exchange administrator, you can export mailboxes, distribution lists
                            etc into .csv files, make changes, and then import it back into exchange,
                            which will create / delete modify these things. The easiest way to see what
                            it is doing, is export your mailboxes to the text file, and have a look. For
                            example the following text (save it to a text file) will create a mailbox,
                            with an associated NT account. Use the Tools\Directory Import command in the
                            exchange administrator. Change the "Primary Windows NT Account", and the
                            "Home-Server" items to your configuration. BTW, these are not all of the
                            available fields, just the ones we need to create this mailbox.

                            "Obj-Class","Mode","First Name","Last name","Display Name","Alias
                            Name","Directory Name","Primary Windows NT
                            Account","Home-Server","Obj-Container"
                            "Mailbox","Create","Test","User","Test
                            User","TestUser","TestUser","TEST\TestUser","TESTPDC","Recipients"

                            If you want to do it programatically, look in the SDK for BatchImport and
                            BatchExport, which are the functions that the admin utilty uses. The format
                            of the file you pass to BatchImport is the same as above.

                            The main options under "Mode" are Create, Delete, and Modify, which are
                            fairly self explanatory. From memory, if you pass modify and the mailbox
                            doesn't exist, it will be created.

Zif.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 1

Author Comment

by:dvaline
Comment Utility
I've been aware of the functions, i have had little success in making them work.
0
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
If you have any plans of migrating your exchange servers to v5.5 in the near future, you should take a look at ADSI (http://backoffice.microsoft.com/downtrial/moreinfo/adsi2.asp). This is a Directory Service interface, which will allow you to add Exchange 5.5 stuff (users/distributionlists etc.), NT 4/5 stuff (users / shares..), IIS stuff, ?? stuff. You can talk to everything that talks LDAP.

0
 
LVL 7

Expert Comment

by:BlackMan
Comment Utility
I've just found this:

Exchange 4.0-5.5 DELPHI 3 interface - NEW VERSION
This unit is FREE for ANY comment`s, notes and etc.., but please for feedback.

Also included small DAPI DCOM SERVER, who create MAILBOX on Exchange Server, and sample Client application for DAPI DCOM SERVER.

Source:      http://www.ccgc.net/dwn/dapi.htm

0
 
LVL 4

Expert Comment

by:d003303
Comment Utility
Yo,
are you still interested in a working answer ? If no, you could delete this question to move it out of the awaiting answers area. If yes, just post a comment.
Slash/d003303
0
 
LVL 1

Author Comment

by:dvaline
Comment Utility
Yes
0
 
LVL 4

Accepted Solution

by:
d003303 earned 1150 total points
Comment Utility
OK,
here's a try. I could not test it because I haven't got an Exchange installation. It is translated from some C++ examples.
If something doesn't work, just post your comments.

unit ExchMailbox;

interface

uses Windows;

// UserName = unique Domain user ID without domain prefix
// FirstName, LastName => Combined to display name
// Server = Exchange server name
// Domain = Domain where the user account resists on
procedure CreateMailbox(UserName, FirstName, LastName, Server, Domain: String);

procedure DeleteMailbox(UserName, Server, Domain: String);

implementation

uses Dapi;

const
  //
  // this has to be customized to your Exchange installation
  //

  // /o -> Organization, /ou -> Organizational Unit
  BasePoint = '/o=MyCompany/ou=MySite';

  // name of the directory where to create the mailbox,
  // Exchange default is 'Recipients'
  Container = 'Recipients';

// internal representation of the two function. You could also include
// user creation by implementing the CreateDeleteUser flag into the
// interfaced functions.
procedure ModifyMailbox(UserName, FirstName, LastName, Server, Domain: String;
                        DoCreate: Boolean; CreateDeleteUser: Boolean);
const objAStr : array[0..4] of string = (
      'Obj-Class', 'Common-Name', 'Home-Server',
      'Primary Windows NT Account', 'Display-Name');

var objDStr      : array[0..4] of string;

    hSession     : DAPI_HANDLE;
    DParams      : DAPI_PARMS;
    Attributes   : DAPI_ENTRY;
    Values       : DAPI_ENTRY;
    StartFlags,
    WriteFlags   : DWORD;
    Index        : Integer;

    AttVal       : array[0..4] of ATT_VALUE;
    AttAttr      : array[0..4] of ATT_VALUE;
begin
  if DoCreate then
   begin
     StartFlags := DAPI_EXPORT_MAILBOX or DAPI_READ_ALL_ATTRIBUTES;
     if CreateDeleteUser
      then StartFlags := StartFlags or DAPI_CREATE_NT_ACCOUNT;
     WriteFlags := DAPI_WRITE_UPDATE or DAPI_RESTRICT_ACCESS;
   end
  else
   begin
     StartFlags := DAPI_EXPORT_MAILBOX or DAPI_READ_ALL_ATTRIBUTES;
     if CreateDeleteUser
      then StartFlags := StartFlags or DAPI_DELETE_NT_ACCOUNT;
     WriteFlags := DAPI_WRITE_DELETE;
   end;

  hSession := nil;
  with DParams do
   begin
     dwDAPISignature := DAPI_SIGNATURE;
     dwFlags := StartFlags;
     pszDSAName := PChar(Server);
     pszBasePoint := PChar(BasePoint);
     pszContainer := PChar(Container);
     pszNTDomain := nil;
     pszCreateTemplate := nil;
     pAttributes := nil;
   end;

  DAPIStart(@hSession, @DParams);

  if DoCreate
   then Attributes.unAttributes := 5
   else Attributes.unAttributes := 4;
  Attributes.ulEvalTag := VALUE_ARRAY;
  Attributes.rgEntryValues := @AttAttr[0];

  for Index := 0 to 4 do
   with AttAttr[Index] do
    begin
      DapiType := DAPI_STRING8;
      Value.pszValue := PChar(objAStr[Index]);
      size := Length(objAStr[Index]) + 1;
      pNextValue := nil;
    end;

  if DoCreate
   then Values.unAttributes := 5
   else Values.unAttributes := 4;
  Values.ulEvalTag := VALUE_ARRAY;
  Values.rgEntryValues := @AttVal[0];

  objDStr[0] := 'Mailbox';
  objDStr[1] := UserName;
  objDStr[2] := Server;
  objDStr[3] := Domain + '\' + UserName;
  objDStr[4] := FirstName + ' ' + LastName;

  for Index := 0 to 4 do
   with AttVal[Index] do
    begin
      DapiType := DAPI_STRING8;
      Value.pszValue := PChar(objDStr[Index]);
      size := Length(objDStr[Index]) + 1;
      pNextValue := nil;
    end;

  DAPIWrite(hSession, WriteFlags,
            @Attributes, @Values, nil, nil, nil);

  DAPIEnd(@hSession);
end;

procedure CreateMailbox(UserName, FirstName, LastName, Server, Domain: String);
begin
  ModifyMailbox(UserName, FirstName, LastName, Server, Domain, true, false);
end;

procedure DeleteMailbox(UserName, Server, Domain: String);
begin
  ModifyMailbox(UserName, '', '', Server, Domain, false, false);
end;

end.

Slash/d003303
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now