C
Christoph Fricke
Hi there,
I want to create a Outlook Distributionlist based on a csv file with
VBS. The script works fine with one limitation.
If the e-mail address is found within the GAL Object and I double click
the ContactItem in the DistributionListItem after the script ran
through the GAL user object is shown. If I add a contact with the same
script whose e-mail address cannot be found within the GAL object and I
double click it, only the e-mail properties of this item are shown
(display name, e-mail address etc.).
The intention of the script is to create only the last type of
ContactItems. Is this possible? If yes, where is the error? I'll add
the raw test code below.
And some other question: Is it possible to check if a
DistributionListItem already exists with VBS?
Thank you in advance for pointing me in the right direction.
Christoph
P.S. The DL already exists during scriptpart execution
I want to create a Outlook Distributionlist based on a csv file with
VBS. The script works fine with one limitation.
If the e-mail address is found within the GAL Object and I double click
the ContactItem in the DistributionListItem after the script ran
through the GAL user object is shown. If I add a contact with the same
script whose e-mail address cannot be found within the GAL object and I
double click it, only the e-mail properties of this item are shown
(display name, e-mail address etc.).
The intention of the script is to create only the last type of
ContactItems. Is this possible? If yes, where is the error? I'll add
the raw test code below.
And some other question: Is it possible to check if a
DistributionListItem already exists with VBS?
Thank you in advance for pointing me in the right direction.
Christoph
P.S. The DL already exists during scriptpart execution
Code:
' add User to DL
addNewDistListMember "DL Test", "Annoying", "[email protected]"
' add DL to DL
addNewDistListMember "DL Test", "DL Test2", "Unknown"
Sub addNewDistListMember(strDistListName, strDistListMemberName,
strDistListMemberMail)
Dim objOutlookApp 'As New Outlook.Application
Dim objOutlookNamespace '
Dim objOutlookContacts '
Dim objDistListItem 'As DistListItem
Dim objMailItem 'As MailItem
Dim objRcpnt 'As Recipient
Set objOutlookApp = CreateObject("Outlook.Application")
Set objOutlookNamespace = objOutlookApp.GetNamespace("MAPI")
Set objOutlookContacts = objOutlookNamespace.GetDefaultFolder(10) '
olFolderContacts
For i = 1 To objOutlookContacts.Items.Count
If TypeName(objOutlookContacts.Items.Item(i)) = "DistListItem" Then
Set objDistListItem = objOutlookContacts.Items.Item(i)
If objDistListItem.DLName = strDistListName Then
Set objMailItem = objOutlookApp.CreateItem(olMailItem)
' if CSV Entry is build like this: DL Test2;DL
Test;Unknown;DistListItem
If instr(strDistListMemberMail, "Unknown") Then
' add DL to DL
Set objRcpnt = objMailItem.Recipients.Add(strDistListMemberName)
If objRcpnt.Resolve Then
wscript.echo " Adding '" & strDistListMemberName & "' to DL '" &
_
strDistListName & "'"
objDistListItem.AddMember objRcpnt
End If
objDistListItem.Save
' if CSV Entry is build like this: DL
Test;Name;[email protected];ContactItem
Else
' add user to DL
Set objRcpnt = objMailItem.Recipients.Add(strDistListMemberName &
Chr(32) & strDistListMemberMail)
If objRcpnt.Resolve Then
wscript.echo " Adding '" & strDistListMemberName & "' to DL '" &
_
strDistListName & "'"
objDistListItem.AddMember objRcpnt
End If
objDistListItem.Save
End If
End If
End If
Next
Set objOutlookApp = Nothing
Set objOutlookNamespace = Nothing
Set objOutlookContacts = Nothing
Set objDistListItem = Nothing
Set objMailItem = Nothing
Set objRcpnt = Nothing
End Sub