Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Word, PowerPoint, Outlook, and Other Office Products > Resolve multiple Distribution List contacts as Email Recipient


Reply
 
Thread Tools Display Modes
  #1  
Old 10-29-2004, 11:02 AM
EracMan's Avatar
EracMan EracMan is offline
Junior Contributor
 
Join Date: Mar 2004
Location: L.A. , CA
Posts: 239
Default Resolve multiple Distribution List contacts as Email Recipient


With the code below, my problem occurs when I attempt to resolve a recipient and Outlook identifies mutiple recipients in the Personal address book that have similar names. I need to be able to resolve this programmatically. Let me Explain:

I am currently using the code below to send emails from an access database using redemption (I can't use Docmd.sendobject b/c the process is automated and docmd.sendobject triggers the outlook security prompt.) I am using this method b/c we have distibution lists in the Personal address book of a specific exchange account and need to send certain reports to certain dist. lists. My problem is that when I pass a distribution list name that is similar to another (Example My distribution list and My Distribution list 1, outlook can't resolve it and the email then sits in the drafts folder until someone manually selects the correct contact and sends it. How can I resolve this issue? Manually, if i clicked on "To:" and selected the correct recipient from the PAB it would work. How can I do this programmatically?

I have thought about simply changing the dist list names but that is a band-aid rather than a long lasting solution.
Code:
Public Sub SendRedemptionEmail(ByVal strRecipients As String, _ Optional ByVal strSubject As String = "", _ Optional ByVal strMessage As String = "", _ Optional ByVal strAttachment As String = "") Dim ProcedureName As String Dim strLogError As String Dim strRecipientList() As String Dim SafeItem, oItem, olApp, Namespace, Utils Dim i As Integer Set Utils = CreateObject("Redemption.MAPIUtils") 'format strRecipients string with semicolons. strRecipients = Replace(strRecipients, ",", ";") strRecipients = Replace(strRecipients, "; ", ";") strRecipientList() = Split(strRecipients, ";") Set olApp = CreateObject("Outlook.Application") Set Namespace = olApp.Getnamespace("MAPI") Namespace.logon 'Create an instance of Redemption.SafeMailItem Set SafeItem = CreateObject("Redemption.SafeMailItem") Set oItem = olApp.CreateItem(0) 'Create a new message SafeItem.Item = oItem 'set Item property For i = LBound(strRecipientList) To UBound(strRecipientList) SafeItem.Recipients.Add strRecipientList(i) Next If strAttachment <> vbNullString _ And Dir(strAttachment) <> "" Then SafeItem.Attachments.Add strAttachment End If SafeItem.Recipients.ResolveAll SafeItem.Subject = strSubject SafeItem.Body = strMessage SafeItem.send Utils.DeliverNow On Error Resume Next Namespace.logoff Set oItem = Nothing Set SafeItem = Nothing Set Namespace = Nothing Set olApp = Nothing Utils.CleanUp Set Utils = Nothing Exit Sub End Sub
__________________
NO other success can compensate for failure in the home” - David O. McKay
Reply With Quote
  #2  
Old 10-29-2004, 01:12 PM
Wamphyri's Avatar
Wamphyri Wamphyri is offline
Variable not defined

Retired Moderator
* Guru *
 
Join Date: Apr 2002
Location: Ottawa, Ontario
Posts: 4,793
Default

Hi EracMan,

I really haven't done much with distribution lists. But I remember removing the code to resolve the recipients actually solved the problem.

A second (and perhaps better solution) would be the look at accessing the distribution lists using CDO (as I've said I have not done much with distribution lists, so I don't know if CDO allows the use of distribution lists).
__________________
-Carl
Reply With Quote
  #3  
Old 10-29-2004, 04:00 PM
EracMan's Avatar
EracMan EracMan is offline
Junior Contributor
 
Join Date: Mar 2004
Location: L.A. , CA
Posts: 239
Default

Wamphyri,
Thanks for the response. I tried your suggestion but unfortunately it will not send the email without a successful resolving of recipients. I did find this post that showed me how to access a distribution list. Using that method it is possible to access a distribution list in the PAB, count all email addresses in the distribution list and then add each address using a for..next loop.

I decided (for now) however to go for the band-aid and change my distribution list name since the above method would require that I account for duplicate email addresses residing in multiple distribution lists (Outlook currently only adds unique email addresses if two or more dist lists contain duplicate email addresses) and that I identify if the address passed to my function is a distribution list or straight email address. It can be done but the ROI at this point doesn't justify the additional time and effort.

I will look into CDO at some point to see if it can be done easier via that route.
__________________
NO other success can compensate for failure in the home” - David O. McKay
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->