Programmatically add/edit contact in Global Address List

Discussion for developers using MailEnable.
Post Reply
Ozmodiar
Posts: 1
Joined: Wed Dec 07, 2011 4:26 pm

Programmatically add/edit contact in Global Address List

Post by Ozmodiar »

Hello

I'm using PHP/AJAX to add contacts to the contactlist of one specific user. What I actually want is to add the contacts to the Global Address List so that every user can see those contacts and I don't have to add them for every user. Is this possible or is there another workaround to do this?

Thanks in advance

Joeri

MailEnable-Ian
Site Admin
Posts: 9738
Joined: Mon Mar 22, 2004 4:44 am
Location: Melbourne, Victoria, Australia

Re: Programmatically add/edit contact in Global Address List

Post by MailEnable-Ian »

Hi,

You could use the directory import option within the administration console. Navigate to: Messaging Manager > Postoffices > (postofficename) > Directory. Right click on directory a select: All task > Import directory entries...
Regards,

Ian Margarone
MailEnable Support

MailEnable
Site Admin
Posts: 4441
Joined: Tue Jun 25, 2002 3:03 am
Location: Melbourne, Victoria Australia

Re: Programmatically add/edit contact in Global Address List

Post by MailEnable »

Also, here is a code example that might help:

Code: Select all

	Dim ItemID As String = "Unique String" 
	
	'ItemID is typically EMail Address Or Guid (if you add one via MMC and look at the directory.tab file, then you will see what one looks like)
	'Note: If  binding the entry to a mailbox ItemID is [MAILBOXNAME] (case is important)

	'Check if it already exists (to see if we are adding it or updating existing)
	Dim oDirectory As New MailEnable.Directory
	APIResult = oDirectory.DirectoryEntry_Clear()
	APIResult = oDirectory.Directory_ClearFilter()
	APIResult = oDirectory.Directory_SetFilterProperty(gc_MEPROP_POSTOFFICE_TAG, gSelectedPostoffice)
	APIResult = oDirectory.Directory_SetFilterProperty(gc_MEPROP_MAILBOX_TAG, gSelectedMailbox)
	APIResult = oDirectory.Directory_SetFilterProperty(gc_MEPROP_DIRECTORYID_TAG, ItemID)

	Dim AlreadyExistsInDirectory As Boolean = (oDirectory.Directory_GetEntry() = 1)

	Dim sLocID As String = ""       
	
	'Note: Use blank - since that handles both new item and editing current item (since the example is dual purpose)

	APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_MEPROP_POSTOFFICE_TAG, gSelectedPostoffice)
	APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_MEPROP_MAILBOX_TAG, gSelectedMailbox)
	APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_MEPROP_DIRECTORYID_TAG, ItemID)

	If Not sFullName Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_MEPROP_DISPLAYNAME_TAG, sFullName)
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_DISPLAY_NAME, sFullName)
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_SUBJECT, sFullName)
	End If
	If Not sEmail Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_MEPROP_EMAIL_TAG, sEmail)
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_EMAIL_ADDRESS, sEmail)
	End If
	If Not sTitle Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_DISPLAY_NAME_PREFIX, sTitle)
	End If
	If Not sFirstName Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_GIVEN_NAME, sFirstName)
	End If
	If Not sMiddleName Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_MIDDLE_NAME, sMiddleName)
	End If
	If Not sLastName Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_SURNAME, sLastName)
	End If
	If Not sNickName Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_MEPROP_NICKNAME_TAG, sNickName)
	End If
	If Not sPhoneW Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_OFFICE_TELEPHONE_NUMBER, sPhoneW)
	End If
	If Not sPhoneM Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_CELLULAR_TELEPHONE_NUMBER, sPhoneM)
	End If
	If Not sPhoneH Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_HOME_TELEPHONE_NUMBER, sPhoneH)
	End If
	If Not sDepartment Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_DEPARTMENT_NAME, sDepartment)
	End If
	If Not sBusiness Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_COMPANY_NAME, sBusiness)
	End If
	If Not sPhotoFileName Is Nothing Then
		Dim sPhotoData As String = GetPhotoData(Session("AUTH_ACCOUNT"), Session("AUTH_USERNAME"), sPhotoFileName)
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_ATTACHMENT_CONTACTPHOTO", sPhotoData)
	End If
	'APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, gc_PROP_NOTE, sNote)
	If Not sStreetAddress Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_STREET_ADDRESS", sStreetAddress)
	End If
	If Not sPostalCode Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_POSTAL_CODE", sPostalCode)
	End If
	If Not sLocality Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_LOCALITY", sLocality)
	End If
	If Not sCountry Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_COUNTRY", sCountry)
	End If
	If Not sProvince Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_STATE_OR_PROVINCE", sProvince)
	End If
	If Not sAssistant Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_ASSISTANT", sAssistant)
	End If

	If Not sHomePage Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_BUSINESS_HOME_PAGE", sHomePage)
	End If
	If Not sPhoneF Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_BUSINESS_FAX_NUMBER", sPhoneF)
	End If
	If Not sPhoneP Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_PAGER_TELEPHONE_NUMBER", sPhoneP)
	End If
	If Not sIM Is Nothing Then
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_MSMESSENGER", sIM)
	End If
	
	If Not sBirthday Is Nothing And sBirthday <> "" Then
		Dim DateArray As String() = Split(sBirthday, "-")
		Dim dtStartDate As Date = New DateTime(CInt(DateArray(0)), CInt(DateArray(1)), CInt(DateArray(2)))
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_BIRTHDAY", dtStartDate)
	Else
		APIResult = oDirectory.DirectoryEntry_SetProperty(sLocID, "PR_BIRTHDAY", "")
	End If

	If AlreadyExistsInDirectory Then
		oDirectory.DirectoryEntry_Commit()
	Else
		APIResult = oDirectory.Directory_CreateEntry()
	End If
	
	oDirectory = Nothing
Regards, Andrew

Post Reply