![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
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 Code:
' add User to DL addNewDistListMember "DL Test", "Annoying", " ' 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 ;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 |
#2
|
|||
|
|||
![]()
There's no error. Everything you've described is normal, expected behavior. A GAL user entry in a DL always points to the GAL record.
If you want to know whether an entry already exists, you'll have to iterate the DL's Members property and check each member's address or name. -- Sue Mosher, Outlook MVP Author of Configuring Microsoft Outlook 2003 http://www.turtleflock.com/olconfig/index.htm and Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Christoph Fricke" wrote in message oups.com... 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 Code:
' add User to DL addNewDistListMember "DL Test", "Annoying", " ' 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 ;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 |
#3
|
|||
|
|||
![]()
Sue,
thank you for answering my question. I understand that this is the expected behavior. So I will try to explain my "script intention" more precisely: ![]() I choose one Distributionlist that already exists, click "add new" (not "choose member" [Actually I only have a german outlook client installed so I do not know the correct english phrase for the buttons (I use OL2k3)]) and enter the name for the object "surname, givenname" and the correct e-mail address, hit OK and the object is added to the Distributionlist. Whether he is in the GAL or not if I double click this member only the e-mail properties of this member item are shown, not the corresponding GAL object. What I try to do is not to add the / a GAL object. I only want to add a new member (with the desired name and e-mail address). Maybe I must use an other way to accomplish the steps described and coded in my first posting!? Can you point me in the right direction? Christoph |
#4
|
|||
|
|||
![]()
This is a limitation of the Outlook Object Model - you can create a one-off
entry id explicitly in MAPI (in this case Outlook will only show the name/address dialog). In the Outlook Object Model however, even if you pass an SMTP address, the GAL address book provider resolves it ot a GAL entry if the SMTP address matches one of the proxy SMTP addresses. There is no way to overwrite this behavior to the best of my knowledge. Sorry for another plug, but in Redemption you can work around that by usingg RDODistListItem.AddMemberEx method - it will create a one-off entry id for you using the specified name/address/address type without going through IAddrBook::ResolveName(). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Christoph Fricke" wrote in message ups.com... Sue, thank you for answering my question. I understand that this is the expected behavior. So I will try to explain my "script intention" more precisely: ![]() I choose one Distributionlist that already exists, click "add new" (not "choose member" [Actually I only have a german outlook client installed so I do not know the correct english phrase for the buttons (I use OL2k3)]) and enter the name for the object "surname, givenname" and the correct e-mail address, hit OK and the object is added to the Distributionlist. Whether he is in the GAL or not if I double click this member only the e-mail properties of this member item are shown, not the corresponding GAL object. What I try to do is not to add the / a GAL object. I only want to add a new member (with the desired name and e-mail address). Maybe I must use an other way to accomplish the steps described and coded in my first posting!? Can you point me in the right direction? Christoph |
#5
|
|||
|
|||
![]()
In this case you will need to create a contact first (ContactItem object),
then manually add it to the DL (when you click "Select Members" as opposed to "Add New"). Outlook links to an existing contact based on its entry id, not on its e-mail address. plugRedemption allows you to a contact to a DL programmatically using RDOContactItem.AddContact - see http://www.dimastr.com/redemption/rd...em.htm#methods /plug To check whether a DL with a given name already exists, simply us MAPIFolder.Items("DistList Name"). If a DL list named "DistList Name" does not exist, you will get an error (which you can trap). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Christoph Fricke" wrote in message oups.com... 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 Code:
' add User to DL addNewDistListMember "DL Test", "Annoying", " ' 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 ;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 |
#6
|
|||
|
|||
![]()
Dmitry,
will you be so kind and give me clue how to accomplish the check for the DL existence? I just want to create the DL if it does not exist and go further with the membership add if it does exist... Christoph |
#7
|
|||
|
|||
![]()
Something along the lines (off the top of my head):
on Error resume next Err.Clear set DL = MAPIFolder.Items("DL Name") if Err.Number 0 Then 'the DL does not exist Err.Clear set DL = MAPIFolder.Items.Add("IPM.DistList") DL.DLName = "DL Name" End If 'do something here DL.Save Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Christoph Fricke" wrote in message oups.com... Dmitry, will you be so kind and give me clue how to accomplish the check for the DL existence? I just want to create the DL if it does not exist and go further with the membership add if it does exist... Christoph |
#8
|
|||
|
|||
![]()
Thank you for your helpful support.
Is it possible to check if an item is already member in this DL by look for the email used or the name of the item in the DistributionList? Which property is best to look after? Christoph |
#9
|
|||
|
|||
![]()
Loop through all the members of the DL (DistListItem.GetMember) and check
the e-mail address (Recpient.Address). Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool "Christoph Fricke" wrote in message oups.com... Thank you for your helpful support. Is it possible to check if an item is already member in this DL by look for the email used or the name of the item in the DistributionList? Which property is best to look after? Christoph |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to add dynamically add controls in Outlook 2003 | Sue Mosher [MVP-Outlook] | Outlook - Using Forms | 4 | May 8th 06 03:38 PM |
Displaying attached picture on a form with VBS ? | philippe | Outlook and VBA | 1 | April 26th 06 05:37 PM |
Outlook automation using vbs | Marceepoo | Outlook - Installation | 1 | January 17th 06 05:18 AM |
How con I add Nodes to my TreeView in OL2003 Forms (VBS) | HelixX23 | Outlook - Using Forms | 1 | January 17th 06 12:26 AM |
Pls comment my VBS | Tony WONG | Outlook and VBA | 1 | January 10th 06 04:34 PM |