Click here to Skip to main content
14,770,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Protected Sub SendMail_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles SendMail.Click

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New  _
Net.NetworkCredential("", "donkeyboat")
            SmtpServer.Port = 587
            SmtpServer.Host = ""
            SmtpServer.EnableSsl = True
            mail = New MailMessage()
            mail.From = New MailAddress("")
            mail.Subject = "Test Mail"
            mail.IsBodyHtml = True
            mail.Body = "This is for testing SMTP mail from GMAIL"

            MsgBox("Mail Send")
        Catch ex As Exception
        End Try
    End Sub

Above is my current code. I would like to do changes for the line to send the mail to. right now i can only send it to one recipient. how do i edit it so that i can send it to many other recipients separated with ';' ?
urgent help is needed. thank you
Updated 14-Jun-12 11:40am

Try this:

string addresses = ";;";
foreach(string address in addresses.split(';'))
Maciej Los 14-Jun-12 17:52pm
Good answer, my 5!
VJ Reddy 14-Jun-12 20:35pm
The answer is good.
But Add method accepts comma separated addresses string as shown in answer, which is succinct I think.
VJ Reddy 14-Jun-12 20:30pm
Good answer. 5!
But Add method accepts comma separated addresses string as shown in answer.
Manas Bhardwaj 15-Jun-12 7:31am
The MailMessage.To property returns a MailMessageCollection as explained here[^].

The Add method of MailMessageCollection accepts a string of mail addresses separated by comma character as explained here[^]

Hence, to send mail to multiple mail addresses use Add method of To property of MailMessage object with the Addresses in a string separated by , as shown below

Manas Bhardwaj 15-Jun-12 7:30am
VJ Reddy 15-Jun-12 7:34am
Thank you, Manas :)
Espen Harlinn 23-Jun-12 4:07am
5'ed! :-D
VJ Reddy 23-Jun-12 8:10am
Thank you, Espen :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900