Sending emails to multiple recipients using vbscript

duper picture duper · Jul 3, 2012 · Viewed 30.6k times · Source

My vbscript sends email to automatically to a recipient, but does anyone know how to add more than one recipient to it?

...
Dim ToAddress
Dim FromAddress
Dim MessageSubject
Dim MyTime
Dim MessageBody
Dim MessageAttachment
Dim ol, ns, newMail
MyTime = Now

ToAddress = "[email protected]"
MessageSubject = "It works!."
MessageBody = "Good job on that script." 
MessageAttachment = some attachment
Set ol = WScript.CreateObject("Outlook.Application")
Set ns = ol.getNamespace("MAPI")
Set newMail = ol.CreateItem(olMailItem)
newMail.Subject = MessageSubject
newMail.Body = MessageBody & vbCrLf & MyTime
newMail.RecipIents.Add(ToAddress)
newMail.Attachments.Add(MessageAttachment)
newMail.Send

This is what I have right now. And it works fine. But, I'd like to have more than one recipients. Thanks in advance.

newMail.CC = "[email protected];[email protected];[email protected]"

This above line worked!

And it works the same way with .BCC, in case anyone wants to not to display the contacts' list.

Answer

Dmitry Streblechenko picture Dmitry Streblechenko · Jul 3, 2012

Call MailItem.Recipients.Add for each recipient or set the To/CC/BCC properties to a ";" separated list of addresses.