Thursday, 22 March 2007

Create Contact Objects in AD in Batch with a Simple VB Script

I have come across a few occasions that I need to create a list of Contact objects for external email addresses in our Active Directory. Most of the time, I ask them to give me the name list in the electronic form. I would then export it to a table to my Access database. I have written a few lines of VB code in this Access database. What it does is that it reads the information from the table and creates Contact objects in the AD.

Here is the code. (Sorry about the indenting. It does not work very well here.)

Private Sub cmdAddContact_Click()

Dim objNewContact ' New Contact to create.
Dim objADAMPath ' Active Directory Application Mode - needed for binding to AD
Dim sPath

sPath =”LDAP:// ou=AddressBook,dc=allaboutexchange, dc=net" ‘where I put all the new Contacts

Dim fName
Dim lName
Dim email
Dim displayname

Dim rsAdContact As Recordset
Dim adContactSQL
Set dbs = CurrentDb

adContactSQL = "Select * From ContactList" ‘ContactList is the table name
Set rsAdContact = CurrentDb.OpenRecordset(adContactSQL, dbOpenDynaset)

Do Until rsAdContact.EOF Or rsAdContact.BOF

fName = rsAdContact("FirstName")
lName = rsAdContact("LastName")
displyname = rsAdContact("DisplayName")
email = rsAdContact("Email1Address")

Set objADAMPath = GetObject(sPath)
sCN = fName & " " & lName & "."
Set objNewContact = objADAMPath.CREATE("Contact", "CN=" & sCN)
If lName <> "" And lName <> vbNullString Then
objNewContact.Put "sn", lName
End If

If fName <> "" And fName <> vbNullString Then
objNewContact.Put "givenName", fName
End If

If email <> "" And email <> vbNullString Then
objNewContact.Put "mail", email
End If

If displyname <> "" And displyname <> vbNullString Then
objNewContact.Put "mailNickname", displyname
End If

If displyname <> "" And displyname <> vbNullString Then
objNewContact.Put "displayName", displyname 'This appears in the GAL
End If

If email <> "" And email <> vbNullString Then
objNewContact.Put "targetAddress", "SMTP:" & email
End If

objNewContact.SetInfo
objNewContact.SetInfo
rsAdContact.MoveNext
Loop

Set objNewContact = Nothing
Set objADAMPath = Nothing

End Sub


Just one more thing, when you run this Access application, you need to have the domain administrator permission to run since you are creating new AD objects.

Saturday, 10 March 2007

Fight Spam with GFI MailEssentials

GFI MailEssentials is an effective anti-spam software package to fight against spam emails. It is fairly simple to set up and after tweaking and training it, it pretty much runs by itself. What I am going to talk about in this article is the feature which allows users to tune the Bayesian engine and blacklist spam emails via Outlook Public Folders.

Open GFI MailEssentials and you will see the filtering functions it provides listed on the left pane. (Figure 1)


Figure 1

From the list you can see GFI MailEssentials uses several filtering technologies to determine what is considered as spam and what is not, including anti-phishing, whitelist, DNS blacklist, custom blacklist, keyword checking, Bayesian analysis etc. Click on one of them and you can see detailed configuration options. (Figure 2)


Figure 2

You can choose to delete the spam or simply move it to the Junk Email folder.

GFI MailEssentials uses Bayesian technology to analyze the content of each message based on certain mathematical rules to decide if the mail is spam. It learns from the outbound email and adapts itself over time by learning about new spam and new valid email. For this feature to work efficiently, you need to train the Bayesian engine. After training it for a while, it results in a 98% spam detection rate.

GFI MailEssentials adds GFI AntiSpam Folders to client’s Outlook Public Folder. When a client receives spam emails in the inbox, he/she can simply drag the spam to This is spam email or Add to blacklist sub-folders. (Figure 3)


Figure 3

After GFI MailEssentials has processed the spam emails, it will put them to the Processed sub-folder.

You can check the detailed spam email detection rate from GFI MailEssentials reporters. (Figure 4, Figure 5, Figure 6)


Figure 4



Figure 5


Figure 6

It is as simple as that.