Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add contacts to a Contact Group in Outlook using VFP9

Status
Not open for further replies.

JohnWMAC

Programmer
Aug 22, 2018
9
US
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
 
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: (provided you are happy to translate the Visual Basic code).

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
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.
 
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.

[pre]Groups
id, groupname

GroupMembers
id, groupid, mail, other data (perhaps even userid)[/pre]

And then get the list of recipients by querying
Code:
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
 
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 [tt]loGroup.SaveAs("MyGroup1")[/tt], 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
 
Olaf and Mike
If I use this:
Code:
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 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top