Solved

Sending emails via a group

Posted on 2009-04-07
3
151 Views
Last Modified: 2013-11-26
Hello All
I need to be able to send mails from my APP internally via exchange server and i have done this OK. Now the customer has seen that this is possible they want to expand on this a little and send to multiple people. I can set up groups such as sales and purchasing and have send mails like this from my APP, once again tested and all OK. Question is can i add users to exchange groups programatically/on the fly or do i need to do this manually before hand, I.E. add user a and user b to purchasing  or  can i select users from a list and write somthing to add them to a group

Hope that makes sense
0
Comment
Question by:bostonste
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 15

Accepted Solution

by:
spprivate earned 500 total points
ID: 24091121
Here is a code .
Courtesy

http://www.outlookcode.com/codedetail.aspx?id=636
Private Sub cmdAdd_Click()
On Error Resume Next
    
    Dim sysPath As String, sSrv As String, sFN As String, sOpenSTR As String
    Dim adoCon As New ADODB.Connection
    Dim adoRS As New ADODB.Recordset
    
    sysPath = App.Path
   
    sSrv = "R01" 'SQL production Database
   
 
    sFN = "Assoc"
 
    strFolderPath = "Public Folders\All Public Folders\" & sFN
    
    arrFolders() = Split(strFolderPath, "\")
    Set objApp = CreateObject("Outlook.Application")
    Set objNS = objApp.GetNamespace("MAPI")
    Set objFolder = objNS.Folders.Item(arrFolders(0))
        
    If Not objFolder Is Nothing Then
        For I = 1 To UBound(arrFolders)
            Set colFolders = objFolder.Folders
            Set objFolder = Nothing
            Set objFolder = colFolders.Item(arrFolders(I))
            If arrFolders(I) = sFN Then
                objFolder.ShowAsOutlookAB = True
                
                Set objDL = objFolder.Items.Add(Outlook.OlItemType.olDistributionListItem)
                objDL.DLName = sFN
                objDL.Save
 
                adoCon.ConnectionString = "driver={SQL Server};" & _
                               "server=" & sSrv & ";Trusted_Connection=Yes;database=RAS"
                If sFN = "Associates" Then
                    sOpenSTR = "'ASC'"
                Else
                    sOpenSTR = "'CR'"
                End If
 
 
                adoRS.Open "Exec RES_AddAssocOrCRS " & sOpenSTR, adoCon.ConnectionString, adOpenDynamic, adLockPessimistic
 
                If Not (adoRS.BOF And adoRS.EOF) Then
                    adoRS.MoveFirst
                    Do Until adoRS.EOF
                        Set objCI = objFolder.Items.Add(olContactItem)
 
                        With objCI
                            .FirstName = adoRS("Fname")
                            .LastName = adoRS("Lname")
                            .Email1Address = adoRS("Email_Address")
                            .Email1DisplayName = adoRS("Display_Name")
                            .SelectedMailingAddress = olHome
                            .Categories = sFN
                            .Save
                        End With
        
                        Set myMailItem = objApp.CreateItem(Outlook.OlItemType.olMailItem)
                        Set oRecipients = myMailItem.Recipients 'Resolve the current user just added by Email Address
                        oRecipients.Add (objCI.Email1Address) 'Add Contact Item as a recipient
                        oRecipients.ResolveAll
                        
                        objDL.AddMembers (oRecipients) ' if count > 109 - it bombs
                        objDL.Display
        
                        Set objCI = Nothing 'in next Iteration
                        Set oRecipients = Nothing 'Empty Contact Item and Recipient Item
            
 
                        adoRS.MoveNext
                    Loop
 
                End If
            End If
            
            If objFolder Is Nothing Then
                Exit For
            End If
        Next I
    End If
    
    Set objDL = Nothing
    
    Set adoRS = Nothing
    Close adoCon
    Set adoCon = Nothing
    Set objFolder = Nothing
    Set colFolders = Nothing
    Set objNS = Nothing
    Set objApp = Nothing
    Unload Me
End Sub

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 24105695
One options is to run a loop and add all the emails to the Recipients collection of the Message rather than first adding to the group.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

734 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