PC Review Forums Newsgroups Microsoft Outlook Microsoft Outlook VBA Programming Adding a distribution list to my own contacts folder.

Reply

Adding a distribution list to my own contacts folder.

 
Thread Tools Rate Thread
Old 07-03-2005, 02:11 PM   #1
neilsg2001@yahoo.co.uk
Guest
 
Posts: n/a
Default Adding a distribution list to my own contacts folder.


Hi,

I have successfully managed to create contacts and put them in into a
distribution list. I have modified this to create the contacts in my
own contacts, (not the root default contacts folder). How do I know
create a distribution list in the new contacts folder?

The current code creates the dist list in the root contact folder and a
move is attempted. This just leaves me with two dist lists which are
both empty.

Thanks in advance.

Neil

**START CODE**
var objOutlook = new ActiveXObject("Outlook.Application")
var objOutlookMsg =
objOutlook.CreateItemFromTemplate(this.templatePath);
var objTempItem = objOutlook.CreateItem(olMailItem);
var objContact
var objRecipients = objTempItem.Recipients;
var objDistList = objOutlook.CreateItem(olDistributionListItem);
objDistList.DLName = GROUPNAME;

var objNamespace = objOutlook.GetNamespace('MAPI');
var objFolder = objNamespace.GetDefaultFolder(olFolderContacts);
var objNewFolder = objFolder.Folders.Add(GROUPNAME);
var objContact = objNewFolder.items.add();
//objDistList.parent = objNewFolder;
//var objDistList = objNewFolder.Folders.add('test',
olDistributionListItem);

var record;
var email;
var objContact;
for (var i=0;i<nodeList.length;i++)
{
record = nodeList[i];
email = record.getAttribute('emailaddress');

//objContact = objOutlook.CreateItem(olContactItem);
//objContact = objNewFolder.items.add();
objContact.email1address = email;
objContact.FileAs = objContact.email1address;
objContact.Save();

objRecipients.add(objContact.email1address);
}

objRecipients.ResolveAll();
objDistList.AddMembers(objRecipients);

objDistList.Save();

objOutlookMsg.Subject = this.subject;
//objOutlookMsg.Body =
objOutlookMsg.Importance = olImportanceNormal;

var objRecipient = objOutlookMsg.Recipients.Add(objDistList.DLName);
objRecipient.Type = olBCC;
objRecipient.Resolve();

objOutlookMsg.Save(); //Save mail to draft folder. You can call
save method to send the email
**END CODE**

  Reply With Quote
Old 07-03-2005, 02:37 PM   #2
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Adding a distribution list to my own contacts folder.

Use the Add method on the target folder's Items collection.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


<neilsg2001@yahoo.co.uk> wrote in message
news:1110204667.957211.158730@f14g2000cwb.googlegroups.com...
> Hi,
>
> I have successfully managed to create contacts and put them in into a
> distribution list. I have modified this to create the contacts in my
> own contacts, (not the root default contacts folder). How do I know
> create a distribution list in the new contacts folder?
>
> The current code creates the dist list in the root contact folder and a
> move is attempted. This just leaves me with two dist lists which are
> both empty.
>
> Thanks in advance.
>
> Neil
>
> **START CODE**
> var objOutlook = new ActiveXObject("Outlook.Application")
> var objOutlookMsg =
> objOutlook.CreateItemFromTemplate(this.templatePath);
> var objTempItem = objOutlook.CreateItem(olMailItem);
> var objContact
> var objRecipients = objTempItem.Recipients;
> var objDistList = objOutlook.CreateItem(olDistributionListItem);
> objDistList.DLName = GROUPNAME;
>
> var objNamespace = objOutlook.GetNamespace('MAPI');
> var objFolder = objNamespace.GetDefaultFolder(olFolderContacts);
> var objNewFolder = objFolder.Folders.Add(GROUPNAME);
> var objContact = objNewFolder.items.add();
> //objDistList.parent = objNewFolder;
> //var objDistList = objNewFolder.Folders.add('test',
> olDistributionListItem);
>
> var record;
> var email;
> var objContact;
> for (var i=0;i<nodeList.length;i++)
> {
> record = nodeList[i];
> email = record.getAttribute('emailaddress');
>
> //objContact = objOutlook.CreateItem(olContactItem);
> //objContact = objNewFolder.items.add();
> objContact.email1address = email;
> objContact.FileAs = objContact.email1address;
> objContact.Save();
>
> objRecipients.add(objContact.email1address);
> }
>
> objRecipients.ResolveAll();
> objDistList.AddMembers(objRecipients);
>
> objDistList.Save();
>
> objOutlookMsg.Subject = this.subject;
> //objOutlookMsg.Body =
> objOutlookMsg.Importance = olImportanceNormal;
>
> var objRecipient = objOutlookMsg.Recipients.Add(objDistList.DLName);
> objRecipient.Type = olBCC;
> objRecipient.Resolve();
>
> objOutlookMsg.Save(); //Save mail to draft folder. You can call
> save method to send the email
> **END CODE**
>



  Reply With Quote
Old 08-03-2005, 09:31 AM   #3
Neil
Guest
 
Posts: n/a
Default Re: Adding a distribution list to my own contacts folder.

Thanks Sue,

Now i have my contacts in a dist list in the sub contacts folder where
I want them.

When i try to use the dist list for the to or bcc field of an email,
neither the contact folder or distlist is available or valid??!!


Neil

  Reply With Quote
Old 08-03-2005, 12:28 PM   #4
Sue Mosher [MVP-Outlook]
Guest
 
Posts: n/a
Default Re: Adding a distribution list to my own contacts folder.

Did you check the box on the Properties dialog of the folder that exposes
that folder through the Outlook Address Book?

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Neil" <neilsg2001@yahoo.co.uk> wrote in message
news:1110274269.114640.113860@l41g2000cwc.googlegroups.com...
> Thanks Sue,
>
> Now i have my contacts in a dist list in the sub contacts folder where
> I want them.
>
> When i try to use the dist list for the to or bcc field of an email,
> neither the contact folder or distlist is available or valid??!!
>
>
> Neil
>



  Reply With Quote
Old 08-03-2005, 04:45 PM   #5
Neil
Guest
 
Posts: n/a
Default Re: Adding a distribution list to my own contacts folder.

Thanks.

myMapiFolder.ShowAsOutlookAB = true

outlook 2002 onwards only - damn



Maybe i'll just put the email addresses in a distribution list in the
root contacts folder and then delete any contacts required to do this
afterwards.

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off