I recently got an email from a user who was trying to send an email to two different people
from an ASP script. He knew he could use CC to copy the second person, but he wanted to
have them both in the To line because other people were going to be CC'd. Here's the
code that he couldn't get to work:
Set objMessage = Server.CreateObject("CDO.Message")
.To = "John <john@some_domain.com>"
.To = "Gary <gary@some_domain.com>"
.From = "Sender <sender@some_domain.com>"
.Subject = "Message Subject"
.TextBody = "Message Body"
Set objMessage = Nothing
While the above code runs without throwing an error, the message only gets sent to one of the users.
The reason this code doesn't work is that the .To property of the Message object works like a
text string. If you set the .To property again, it doesn't add another user to the list of recipients,
it overwrites the existing value with the new value. So how do you send a message to more than one user?
Here's my reply to the user:
You're right that the .To property of the CDO Message object is just a text field, but that doesn't
mean you can't send email to multiple people. I usually use the .CC to copy people, but you can
also just use a semi-colon delimited list to send to multiple people via the .To field. Like this:
.To = "John <john@some_domain.com>; Gary <gary@some_domain.com>"