×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Add contacts to a Contact Group in Outlook using VFP9

Add contacts to a Contact Group in Outlook using VFP9

Add contacts to a Contact Group in Outlook using VFP9

(OP)
Brand new to Tek-Tips so sorry if I am a bit clumsy. Just trying to write a small program in VFP9 to add existing contacts to a new contact group. Reason for automation is that there are THOUSANDS of contacts and I need to get them into reasonably small groups so my email provider doesn't flag me for too many recipients in a single email. I've written several similar programs in the past so I have reasonable experience....just looking for help in this SPECIFIC area....THANKS

RE: Add contacts to a Contact Group in Outlook using VFP9

Hello John, and welcome to the forum. I can't give you a complete answer, as I don't have any experience of using contact groups in Outlook (nor with distribution lists, which I think is actually what you want).

However,the following code might point you in the right direction:

CODE -->

loOut = CREATEOBJECT("outlook.application")
loGroup = loOut.CreateItem(10)   
loMailItem = loOut.CreateItem(0)
loRecips = loMailItem.Recipients
loRecips.Add("John WMac")
loRecips.Add("Mike Lewis")
&& etc. etc.
loRecips.ResolveAll
loGroup.AddMembers(loRecips) 

In practice, you would use a FOR EACH loop to add the individual recipients, using whatever criteria you think appropriate.

Note that I haven't tested the above code, nor can I be sure that it is the best way to solve the problem. My aim is to give you a general idea to get you started.

You might also find this page useful: https://docs.microsoft.com/en-us/office/vba/api/ou... (provided you are happy to translate the Visual Basic code).

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Add contacts to a Contact Group in Outlook using VFP9

(OP)
Thanks Mike. I think I can work with this. As I said, I do have some experience in this area. I will let you know how I make out.

RE: Add contacts to a Contact Group in Outlook using VFP9

Mike showed how to add recipients to an outlook contact group (actually item type 10 doesn't work for me, I find 7 is a distribution list).

It's unclear how many recipients your ISP allows, a distribution list in the end also is turned into recipients. I've seen different limits when I just wrote mailings for a sports club. It's been a while.

If all the recipients don't know each other and if you don't want to get classified (even just when temporary) as spammer, you would need to conform to certain rules, of which one would be to send a mail per client, even if you don't individualize the mail text.

I did use BCC and used noreply@domain.com as main normal recipient, but that's recognized by every recipient as the very weird situation of getting a mail from an account to itself.

Today I'd always rather use a provider for campaigns or newsletter service than rolling your own. There's a lot more technical business to do with SPF header and many more things I don't even would like to know about, but perhaps that IS your thing.

I would add a few thoughts on how to create groups on your own in data. Well, first of all, you can stay with distribution lists in outlook and then just have that list name as one recipient, but that's very specific to Outlook. It's not hard to design a little database of mail groups with two tables.

Groups
id, groupname

GroupMembers
id, groupid, mail, other data (perhaps even userid) 

And then get the list of recipients by querying

CODE --> sendmails

Lparameters tcGroupname 

Select * from groups g left join groupmembers gm on gm.group.id = g.id Where groupname=tcGroupname Into Cursor crsRecipients
loMailItem=.null.
Scan
   If Isnull(loMailitem)
      loMailitem = this.createmailbody(tcGroupname)
   Endif
   loMailItem.Recipients.Add(mail)
   if recno()%50=0
      loMailItem.Send()
      loMailItem = .NULL.
   Endif
Endscan 
If !Isnull(loMailitem)
   loMailitem.Send()
Endif 

With createmailbody being a separate method of that class to create such a mail item without recipients, could also be a PRG or function. Making tcGroupname a parameter of that too is just a suggestion, I'd perhaps have mail templates named like the group of recipients for them and as suggested above GroupMembers could really just link Groups and Users so a user can subscribe to multiple mailings.

Bye, Olaf.

Olaf Doschke Software Engineering
https://www.doschke.name

RE: Add contacts to a Contact Group in Outlook using VFP9

Quote:

actually item type 10 doesn't work for me, I find 7 is a distribution list

That's right. I misread the enum list.

John, the above correction relates to the second line in my code.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Add contacts to a Contact Group in Outlook using VFP9

Of course you would also need to save the list after you create it (I suppose that's obvious, but I should have mentioned it anyway).

You can simply do loGroup.SaveAs("MyGroup1"), for example.

Alternatively, of course, you could create and save all the groups within Outlook itself, and just add the recipients within VFP - depending on how dynamic the groups and recipients are.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads

RE: Add contacts to a Contact Group in Outlook using VFP9

Olaf and Mike
If I use this:

CODE --> foxpro

loOutlook = CREATEOBJECT("Outlook.Application")
loNamespace = loOutlook.GetNamespace("MAPI")
loFolder= loNamespace.GetDefaultFolder(10)
loFolder.display() 

It opens up my contact in Outlook.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483: How to get the best response from the forum first.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close