CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Send email

  1. #1
    Join Date
    Oct 2000
    Posts
    34

    Send email

    Hi, all
    I found the folloing code on the Microsoft site and it works just fine. But I need some advise. Does anybody know how to send the message to more then one recipient without using the loop? Thanks

    On the Tools menu, choose References and select the Microsoft CDO 1.21 Library

    Private Sub Command1_Click()
    Dim objSession As Object
    Dim objMessage As Object
    Dim objRecipient As Object

    'Create the Session Object
    Set objSession = CreateObject("mapi.session")

    'Logon using the session object
    'Specify a valid profile name if you want to
    'Avoid the logon dialog box
    objSession.Logon profileName:="MS Exchange Settings"

    'Add a new message object to the OutBox
    Set objMessage = objSession.Outbox.Messages.Add

    'Set the properties of the message object
    objMessage.subject = "This is a test."
    objMessage.Text = "This is the message text."

    'Add a recipient object to
    'the objMessage.Recipients collection
    Set objRecipient = objMessage.Recipients.Add

    'Set the properties of the recipient object
    objRecipient.Name = "John Doe" '<---Replace
    'this with a valid
    'display name or e-mail alias
    objRecipient.Type = mapiTo
    objRecipient.Resolve

    'Send the message
    objMessage.Send showDialog:=False
    MsgBox "Message sent successfully!"

    'Logoff using the session object
    objSession.Logoff
    End Sub






  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Send email

    Use the Index (or RecipIndex, I don't remember) property as follows:


    'set the properties of the recipient object
    objRecipient.Index = 0
    objRecipient.Name = "John Doe" '<---Replace
    'this with a valid
    'display name or e-mail alias
    objRecipient.Type = mapiTo
    objRecipient.Resolve

    objRecipient.Index = 1
    objRecipient.Name = "Foo Bar" '<---Replace
    'this with a valid
    'display name or e-mail alias
    objRecipient.Type = mapiTo
    objRecipient.Resolve





  3. #3
    Join Date
    Oct 2000
    Posts
    34

    Re: Send email

    Thank you for reply. You are almost right.
    The loop should be created for loading of objMessage.Recipients collection only

    There is the answer:

    'Add a recipient object to the objMessage.Recipients collection

    Set objRecipient = objMessage.Recipients.Add
    'Set the properties of the recipient object
    objRecipient.Name = "some name"
    objRecipient.Type = mapiTo
    objRecipient.Resolve
    MsgBox objRecipient.Index 'read only property =1
    '**********************************************
    Set objRecipient = objMessage.Recipients.Add
    'Set the properties of the recipient object
    objRecipient.Name = "another name"
    objRecipient.Type = mapiTo
    objRecipient.Resolve
    MsgBox objRecipient.Index '=2


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured