Solved

VBScript: Error while creating distribution list in Outlook

Posted on 2011-02-20
3
715 Views
Last Modified: 2012-05-11
Hello experts,

We need to create a distribution list in Outlook from a VBScript.
When the number of email addresses to add in the list is small (<90), everytihing is working well.
But when this number approaches 100, we get an error 80004004 and the process is aborted.

According to our tests, the number of addresses from which we have an error is not fixed.
And it seems the error is more related to the total size (in character) of the whole list than to the number of addresses we try to put in this list.
This is the code used to create the list:
Dim myOlApp, myDistList, myMailItem, myRecipients
Set myOlApp = WScript.CreateObject("Outlook.Application")
Set myDistList = myOlApp.CreateItem(7)
myDistList.DLName = InputBox("Enter the name of the new distribution list.")
Set myMailItem = myOlApp.CreateItem(0) 
Set myRecipients = myMailItem.Recipients
myRecipients.Add "address1@gmail.com"
myRecipients.Add "address2@gmail.com"
myRecipients.Add "address3@gmail.com"
...
myRecipients.Add "lastaddress@gmail.com"
myRecipients.ResolveAll
myDistList.AddMembers myRecipients
myDistList.Save
myDistList.Display

Open in new window

The error is occuring on the "myDistList.Save" instruction.
Do you have any idee of how to avoid this error?

For your info, the script is generated/downloaded from a JSP page.

Many thanks in advance for your help.

ossAdmin
0
Comment
Question by:ossAdmin
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 34939143
Comment out myDistList.Save, and then try to save the list when it displays.  You will get an error message saying that the list is too large.

I was able to run it successfully with 100 members, but not 200 members, so I suspect that the limit is set in the Exchange Server set-up.

A work-around would be to create sub-DLs, and then a master DL that includes each of the subs.

This quick and dirty script worked for me on that score:




Dim myOlApp, myDistList, myMailItem, myRecipients, Recip
Dim Name1, Name2, Name3
Set myOlApp = CreateObject("Outlook.Application")
Set myDistList = myOlApp.CreateItem(7)
Name1 = InputBox("Enter the name of the first sub-distribution list.")
Name2 = InputBox("Enter the name of the second sub-distribution list.")
Name3 = InputBox("Enter the name of the master distribution list.")

myDistList.DLName = Name1
Set myMailItem = myOlApp.CreateItem(0) 
Set myRecipients = myMailItem.Recipients
myRecipients.Add "address1@gmail.com"
myRecipients.Add "address2@gmail.com"
myRecipients.Add "address3@gmail.com"

'...
myRecipients.Add "address4@gmail.com"
myRecipients.Add "address5@gmail.com"
myRecipients.Add "address6@gmail.com"
myRecipients.Add "address7@gmail.com"
myRecipients.Add "address8@gmail.com"
myRecipients.Add "address9@gmail.com"
myRecipients.Add "address10@gmail.com"
myRecipients.Add "address11@gmail.com"
myRecipients.Add "address12@gmail.com"
myRecipients.Add "address13@gmail.com"
myRecipients.Add "address14@gmail.com"
myRecipients.Add "address15@gmail.com"
myRecipients.Add "address16@gmail.com"
myRecipients.Add "address17@gmail.com"
myRecipients.Add "address18@gmail.com"
myRecipients.Add "address19@gmail.com"
myRecipients.Add "address20@gmail.com"
myRecipients.Add "address21@gmail.com"
myRecipients.Add "address22@gmail.com"
myRecipients.Add "address23@gmail.com"
myRecipients.Add "address24@gmail.com"
myRecipients.Add "address25@gmail.com"
myRecipients.Add "address26@gmail.com"
myRecipients.Add "address27@gmail.com"
myRecipients.Add "address28@gmail.com"
myRecipients.Add "address29@gmail.com"
myRecipients.Add "address30@gmail.com"
myRecipients.Add "address31@gmail.com"
myRecipients.Add "address32@gmail.com"
myRecipients.Add "address33@gmail.com"
myRecipients.Add "address34@gmail.com"
myRecipients.Add "address35@gmail.com"
myRecipients.Add "address36@gmail.com"
myRecipients.Add "address37@gmail.com"
myRecipients.Add "address38@gmail.com"
myRecipients.Add "address39@gmail.com"
myRecipients.Add "address40@gmail.com"
myRecipients.Add "address41@gmail.com"
myRecipients.Add "address42@gmail.com"
myRecipients.Add "address43@gmail.com"
myRecipients.Add "address44@gmail.com"
myRecipients.Add "address45@gmail.com"
myRecipients.Add "address46@gmail.com"
myRecipients.Add "address47@gmail.com"
myRecipients.Add "address48@gmail.com"
myRecipients.Add "address49@gmail.com"
myRecipients.Add "address50@gmail.com"
myRecipients.Add "address51@gmail.com"
myRecipients.Add "address52@gmail.com"
myRecipients.Add "address53@gmail.com"
myRecipients.Add "address54@gmail.com"
myRecipients.Add "address55@gmail.com"
myRecipients.Add "address56@gmail.com"
myRecipients.Add "address57@gmail.com"
myRecipients.Add "address58@gmail.com"
myRecipients.Add "address59@gmail.com"
myRecipients.Add "address60@gmail.com"
myRecipients.Add "address61@gmail.com"
myRecipients.Add "address62@gmail.com"
myRecipients.Add "address63@gmail.com"
myRecipients.Add "address64@gmail.com"
myRecipients.Add "address65@gmail.com"
myRecipients.Add "address66@gmail.com"
myRecipients.Add "address67@gmail.com"
myRecipients.Add "address68@gmail.com"
myRecipients.Add "address69@gmail.com"
myRecipients.Add "address70@gmail.com"
myRecipients.Add "address71@gmail.com"
myRecipients.Add "address72@gmail.com"
myRecipients.Add "address73@gmail.com"
myRecipients.Add "address74@gmail.com"
myRecipients.Add "address75@gmail.com"
myRecipients.Add "address76@gmail.com"
myRecipients.Add "address77@gmail.com"
myRecipients.Add "address78@gmail.com"
myRecipients.Add "address79@gmail.com"
myRecipients.Add "address80@gmail.com"
myRecipients.Add "address81@gmail.com"
myRecipients.Add "address82@gmail.com"
myRecipients.Add "address83@gmail.com"
myRecipients.Add "address84@gmail.com"
myRecipients.Add "address85@gmail.com"
myRecipients.Add "address86@gmail.com"
myRecipients.Add "address87@gmail.com"
myRecipients.Add "address88@gmail.com"
myRecipients.Add "address89@gmail.com"
myRecipients.Add "address90@gmail.com"
myRecipients.Add "address91@gmail.com"
myRecipients.Add "address92@gmail.com"
myRecipients.Add "address93@gmail.com"
myRecipients.Add "address94@gmail.com"
myRecipients.Add "address95@gmail.com"
myRecipients.Add "address96@gmail.com"
myRecipients.Add "address97@gmail.com"
myRecipients.Add "address98@gmail.com"
myRecipients.Add "address99@gmail.com"
myRecipients.Add "address100@gmail.com"

myRecipients.ResolveAll
myDistList.AddMembers myRecipients
myDistList.Save
Set myRecipients = Nothing
Set myMailItem = Nothing
Set myDistList = Nothing

Set myDistList = myOlApp.CreateItem(7)
myDistList.DLName = Name2
Set myMailItem = myOlApp.CreateItem(0) 
Set myRecipients = myMailItem.Recipients

myRecipients.Add "address101@gmail.com"
myRecipients.Add "address102@gmail.com"
myRecipients.Add "address103@gmail.com"
myRecipients.Add "address104@gmail.com"
myRecipients.Add "address105@gmail.com"
myRecipients.Add "address106@gmail.com"
myRecipients.Add "address107@gmail.com"
myRecipients.Add "address108@gmail.com"
myRecipients.Add "address109@gmail.com"
myRecipients.Add "address110@gmail.com"
myRecipients.Add "address111@gmail.com"
myRecipients.Add "address112@gmail.com"
myRecipients.Add "address113@gmail.com"
myRecipients.Add "address114@gmail.com"
myRecipients.Add "address115@gmail.com"
myRecipients.Add "address116@gmail.com"
myRecipients.Add "address117@gmail.com"
myRecipients.Add "address118@gmail.com"
myRecipients.Add "address119@gmail.com"
myRecipients.Add "address120@gmail.com"
myRecipients.Add "address121@gmail.com"
myRecipients.Add "address122@gmail.com"
myRecipients.Add "address123@gmail.com"
myRecipients.Add "address124@gmail.com"
myRecipients.Add "address125@gmail.com"
myRecipients.Add "address126@gmail.com"
myRecipients.Add "address127@gmail.com"
myRecipients.Add "address128@gmail.com"
myRecipients.Add "address129@gmail.com"
myRecipients.Add "address130@gmail.com"
myRecipients.Add "address131@gmail.com"
myRecipients.Add "address132@gmail.com"
myRecipients.Add "address133@gmail.com"
myRecipients.Add "address134@gmail.com"
myRecipients.Add "address135@gmail.com"
myRecipients.Add "address136@gmail.com"
myRecipients.Add "address137@gmail.com"
myRecipients.Add "address138@gmail.com"
myRecipients.Add "address139@gmail.com"
myRecipients.Add "address140@gmail.com"
myRecipients.Add "address141@gmail.com"
myRecipients.Add "address142@gmail.com"
myRecipients.Add "address143@gmail.com"
myRecipients.Add "address144@gmail.com"
myRecipients.Add "address145@gmail.com"
myRecipients.Add "address146@gmail.com"
myRecipients.Add "address147@gmail.com"
myRecipients.Add "address148@gmail.com"
myRecipients.Add "address149@gmail.com"
myRecipients.Add "address150@gmail.com"
myRecipients.Add "address151@gmail.com"
myRecipients.Add "address152@gmail.com"
myRecipients.Add "address153@gmail.com"
myRecipients.Add "address154@gmail.com"
myRecipients.Add "address155@gmail.com"
myRecipients.Add "address156@gmail.com"
myRecipients.Add "address157@gmail.com"
myRecipients.Add "address158@gmail.com"
myRecipients.Add "address159@gmail.com"
myRecipients.Add "address160@gmail.com"
myRecipients.Add "address161@gmail.com"
myRecipients.Add "address162@gmail.com"
myRecipients.Add "address163@gmail.com"
myRecipients.Add "address164@gmail.com"
myRecipients.Add "address165@gmail.com"
myRecipients.Add "address166@gmail.com"
myRecipients.Add "address167@gmail.com"
myRecipients.Add "address168@gmail.com"
myRecipients.Add "address169@gmail.com"
myRecipients.Add "address170@gmail.com"
myRecipients.Add "address171@gmail.com"
myRecipients.Add "address172@gmail.com"
myRecipients.Add "address173@gmail.com"
myRecipients.Add "address174@gmail.com"
myRecipients.Add "address175@gmail.com"
myRecipients.Add "address176@gmail.com"
myRecipients.Add "address177@gmail.com"
myRecipients.Add "address178@gmail.com"
myRecipients.Add "address179@gmail.com"
myRecipients.Add "address180@gmail.com"
myRecipients.Add "address181@gmail.com"
myRecipients.Add "address182@gmail.com"
myRecipients.Add "address183@gmail.com"
myRecipients.Add "address184@gmail.com"
myRecipients.Add "address185@gmail.com"
myRecipients.Add "address186@gmail.com"
myRecipients.Add "address187@gmail.com"
myRecipients.Add "address188@gmail.com"
myRecipients.Add "address189@gmail.com"
myRecipients.Add "address190@gmail.com"
myRecipients.Add "address191@gmail.com"
myRecipients.Add "address192@gmail.com"
myRecipients.Add "address193@gmail.com"
myRecipients.Add "address194@gmail.com"
myRecipients.Add "address195@gmail.com"
myRecipients.Add "address196@gmail.com"
myRecipients.Add "address197@gmail.com"
myRecipients.Add "address198@gmail.com"
myRecipients.Add "address199@gmail.com"
'...

myRecipients.Add "lastaddress@gmail.com"
myRecipients.ResolveAll
myDistList.AddMembers myRecipients
myDistList.Save

Set myRecipients = Nothing
Set myMailItem = Nothing
Set myDistList = Nothing

Set myDistList = myOlApp.CreateItem(7)
myDistList.DLName = Name3
Set Recip = myOlApp.Session.CreateRecipient(Name1)
Recip.Resolve
myDistList.AddMember Recip
Set Recip = myOlApp.Session.CreateRecipient(Name2)
Recip.Resolve
myDistList.AddMember Recip
Set Recip = Nothing

myDistList.Save
Set myDistList = Nothing

Set myOlApp = Nothing

Open in new window

0
 

Author Comment

by:ossAdmin
ID: 34940889
Hello matthewspatrick,

Thanks a lot for your reply.
Yesterday I indeed found the same information here. The information in this link is not 100% correct (I'm running Outlook SP3 and still have the size limitation).

Your proposal is I think the best (and only?) solution to this issue. And I hope our users will accept it (which is another story...).

Many thanks again.

ossAdmin.
0
 

Author Comment

by:ossAdmin
ID: 34972932
Hello matthewspatrick,

I've closed this question too soon...
I've been trying to implement the sub-lists solution you proposed, as well as several variants without success.

The result is always the same: the sub-lists are well created, but the main list remains empty.

Could you please explain how you've manage to make it work?

Many thanks in advance.

ossAdmin.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to dynamically set the form action using jQuery.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now