Solved

Exchange Server from D3

Posted on 1998-06-13
12
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +2
12 Comments
 
LVL 8

Expert Comment

by:ZifNab
ID: 1352636
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
ID: 1352637
0
 
LVL 1

Author Comment

by:dvaline
ID: 1352638
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!

 
LVL 5

Expert Comment

by:ronit051397
ID: 1352639
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
ID: 1352640
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1352641
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
 
LVL 1

Author Comment

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

Expert Comment

by:BlackMan
ID: 1352643
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
ID: 1352644
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
ID: 1352645
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
ID: 1352646
Yes
0
 
LVL 4

Accepted Solution

by:
d003303 earned 1150 total points
ID: 1352647
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to debug For loops? 3 63
Convert a string into a TDateTime 5 72
how to change, disabled button color FMX ? 1 51
Broadcast a message using ICS 2 28
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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