[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 228
  • Last Modified:

Exchange Server from D3

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
dvaline
Asked:
dvaline
  • 3
  • 3
  • 2
  • +2
1 Solution
 
ZifNabCommented:
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
 
dvalineAuthor Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ronit051397Commented:
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
 
ronit051397Commented:
0
 
ZifNabCommented:
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
 
dvalineAuthor Commented:
I've been aware of the functions, i have had little success in making them work.
0
 
BlackManCommented:
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
 
BlackManCommented:
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
 
d003303Commented:
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
 
dvalineAuthor Commented:
Yes
0
 
d003303Commented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 3
  • 3
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now