0

I am testing how to send an e-mail. I have copied the code below from the help files:

Sub CreateHTMLMail()
'Creates a new e-mail item and modifies its properties'

    Dim olApp As Outlook.Application
    Dim objMail As Outlook.MailItem
    Set olApp = Outlook.Application
    'Create e-mail item'
    Set objMail = olApp.CreateItem(olMailItem)

    With objMail
        .Subject = "Test Message"
        .Body = "Body Text"
        .Recipients.Add "xyz@abc.com"
        .Recipients.ResolveAll
        .Display
    End With
End Sub

I receive a Runtime error '287' message with the .Recipients.Add line highlighted. What am I doing wrong?

Community
  • 1
  • 1
Steve
  • 1,149
  • 3
  • 12
  • 13
  • Just a quick comment... if you want the message to send automatically without having to open outlook, just use the `.Send` property at the end of your `With` – Tommy O'Dell Oct 15 '11 at 04:01

2 Answers2

1

Edit:
As the OP states in his comment to my original answer, changing his code to

.Recipients.To = "abc@xyz.com" 

solved his problem. I leave my original answer below, because someone may learn from the mistake I made, pointed out by divo ;-)


Original answer (careful, this is wrong!):

Try enclosing the parameters passed to the Add method with parentheses:
.Recipients.Add ("xyz@abc.com")

Community
  • 1
  • 1
Treb
  • 19,903
  • 7
  • 54
  • 87
1

Try this:

   toString = "me@email.com;you@email.com;them@email.com"

    With OutMail
        .To = toString
        .Subject = "Hello Friends"
        .Body = "Here is the email body"
        .Send
    End With

This of course works with multiple recipients. For a single recipient, just do this:

toString = "oneguy@gmail.com"

And don't forget the .Send to actually make your email send.

Tommy O'Dell
  • 7,019
  • 13
  • 56
  • 69