Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FIM/MIM - Defining a Unique Email Address
Case "mail-ADMA-Export"
'MV attributes required are: provisionExchangeMailbox, firstName, sn, initials, company, orgSite, department
'Pump out attribute required for mailbox provision
If mventry.Item("provisionExchangeMailbox").IsPresent Then
If Not csentry.Item("mail").IsPresent Then 'Mail attribute is not present
If mventry.Item("provisionExchangeMailbox").Value.ToLower = "true" Then
'Lets start trying to generate a new email address for this user...
'Start calculating the suffix:
Dim mailSuffix As String = ""
Dim mailPrefix As String = ""
If mventry.Item("firstName").IsPresent And mventry.Item("sn").IsPresent Then
If mventry.Item("orgSite").IsPresent Then
If mventry.Item("orgSite").Value.ToLower = "oxford" Or mventry.Item("orgSite").Value.ToLower = "edinburgh" Then
mailSuffix = "@abcd.co.uk"
End If
End If
If mventry.Item("company").IsPresent Then
If mventry.Item("company").Value.ToLower = "abcd" Then
mailSuffix = "@abcd.co.uk"
ElseIf mventry.Item("company").Value.ToLower = "lmno" Then
mailSuffix = "@lmno.co.uk"
ElseIf mventry.Item("company").Value.ToLower = "wxyz" Then
mailSuffix = "@wxyz.co.uk"
End If
End If
If mventry.Item("department").IsPresent Then
If mventry.Item("department").Value.ToLower = "lmno" Then
mailSuffix = "@lmno.co.uk"
ElseIf mventry.Item("department").Value.ToLower = "pqrs" Then
mailSuffix = "@pqrs.co.uk"
End If
End If
'Next generate a prefix...
'1. firstname.lastname
mailPrefix = mventry.Item("firstName").Value & "." & mventry.Item("sn").Value
'Then go check if it has already been used by looking in the MV.
Dim AdminEntry1() As MVEntry = Utils.FindMVEntries("mail", mailPrefix & mailSuffix)
If AdminEntry1.Length = 0 Then
csentry.Item("mail").Value = mailPrefix & mailSuffix
ElseIf AdminEntry1.Length <> 0 Then
'That address is already used, so lets try creating a new prefix...
'2. firstname.initial.lastname
mailPrefix = mventry.Item("firstName").Value & "." & mventry.Item("initials").Value & "." & mventry.Item("sn").Value
Dim AdminEntry2() As MVEntry = Utils.FindMVEntries("mail", mailPrefix & mailSuffix)
If AdminEntry2.Length = 0 Then
csentry.Item("mail").Value = mailPrefix & mailSuffix
ElseIf AdminEntry2.Length <> 0 Then
'That address is already used, so lets try creating a new prefix...
'3. initials.lastname
mailPrefix = mventry.Item("initials").Value & "." & mventry.Item("sn").Value
Dim AdminEntry3() As MVEntry = Utils.FindMVEntries("mail", mailPrefix & mailSuffix)
If AdminEntry3.Length = 0 Then
csentry.Item("mail").Value = mailPrefix & mailSuffix
ElseIf AdminEntry3.Length <> 0 Then
'That address is already used, so lets try creating a new prefix...
'4. firstname.lastname<n>
Dim rnd As New Random()
Dim prefixNum As Integer = rnd.Next(1, 9)
mailPrefix = mventry.Item("firstName").Value & "." & mventry.Item("sn").Value & prefixNum
Dim AdminEntry4() As MVEntry = Utils.FindMVEntries("mail", mailPrefix & mailSuffix)
If AdminEntry4.Length = 0 Then
csentry.Item("mail").Value = mailPrefix & mailSuffix
ElseIf AdminEntry4.Length <> 0 Then
Throw New Exception("Unable to allocate Email Address")
End If
End If
End If
End If
End If
End If
End If
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.