ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash



 Top ASP 101 Stories Top ASP 101 Stories
An Overview of ASP.NET
Connections, Commands, And Procedures
What is ASP?

QUICK TIP:
Is The User Still There?
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates


Quick Tips


Sending an Email to Multiple Recipients

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")
With objMessage
  .To       = "John <john@some_domain.com>"
  .To       = "Gary <gary@some_domain.com>"
  .From     = "Sender <sender@some_domain.com>"
  .Subject  = "Message Subject"
  .TextBody = "Message Body"
  .Send
End With
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>"

or if you don't care about the display names:

.To = "john@some_domain.com; gary@some_domain.com"

Hopefully this will help people understand why the first set of code doesn't work and clear up the confusion about how to send an email message to multiple recipients.


Previous      Show All Tips      Next

If you have a tip you would like to submit, please send it to: webmaster@asp101.com.


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers