MailMessage() - Sending Email to Multiple Recipients

SharkBait
08-15-2007, 11:32 AM
Hi,

I've been using MailMessage() to send some basic emails to customers and I was curious if anyone knows how I can either a) send to multiple recipients or b) Cc people in on the email that I send out.


Dim MailMSG as New MailMessage(sFROM, sTO, sSubject, sBody)

SMTPClient.Host = "127.0.0.1"
SMTClient.UseDefaultCredentials = True

Try
SMTPClient.Send(MailMSG)
Catch ex as Exception

End Try

SMTPClient = Nothing


Now looking over the help file for MailMessage there is a Cc property as well as a Bcc property though I am unsure how they work.

If I was to use the sTo variable, could I comma or semi-colon delimit the email addresses to have it sent to multiple people?

AtmaWeapon
08-15-2007, 11:44 AM
Since To, Bcc, and CC are all of type MailAddressCollection, you use the Add method to add addresses.

Supposing your message is already created:message.CC.Add("email@somewhere.com")

SharkBait
08-15-2007, 11:45 AM
Oh, that makes it a lot easier! Thank you!

MKoslof
08-15-2007, 12:04 PM
If I was to use the sTo variable, could I comma or semi-colon delimit the email addresses to have it sent to multiple people?


Absolutely, say you want more than one person as your "TO" target, you aren't forced to put extras in the CC or BCC, but yes, it involves a little string parsing but you are in control of your delimiter.

1) String array toRecips = passedString Split at delimiter
2) For each string in toRecips, mailMessage.To.Add(string value)

As already mentioned you can use the CC and BCC in the same regard, just pass in a string address or a new instance of the MailAddress object.

SharkBait
08-15-2007, 12:59 PM
Oh that made sense and it works nicely!

Thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum