Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sending email to more than one address
Message
From
14/06/2007 09:44:51
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
 
 
To
14/06/2007 09:40:42
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, United States
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01232983
Message ID:
01232987
Views:
11
>Using VS2005, I am trying to send an email to more than one address. How do I specify more that one address in the "To"? Is there a delimiter between the addresses?
>
>
>MailAddress from = new MailAddress("Myfrom@address.com");
>MailAddress to = new MailAddress("MyTo1@address.com");
>MailMessage message = new MailMessage(from, to);
>
>
>Thanks,
>
>Jerry

Here are some functions from a class I have been working on. It is a work in progress, and right now it only accepts one recipient parameter, but you should be able to see that the msg.to property is a collection.
Public Sub Send(ByVal from As String, _
                    ByVal recipient As String, _
                    ByVal cc As String, _
                    ByVal bcc As String, _
                    ByVal subject As String, _
                    ByVal body As String, _
                    ByVal priority As MailPriority, _
                    Optional ByVal isBodyHTML As Boolean = False)

        Dim msg As MailMessage

        Try
            msg = New MailMessage
            msg.From = New MailAddress(from)
            msg.To.Add(recipient)

            If cc.Length > 0 Then
                msg.CC.Add(cc)
            End If

            If bcc.Length > 0 Then
                msg.Bcc.Add(bcc)
            End If

            msg.Subject = subject
            msg.Body = body
            msg.Priority = priority
            msg.IsBodyHtml = isBodyHTML

            Me.Send(msg)
        Catch ex As Exception
            Throw New ApplicationException("Error sending email.")
        Finally
            If Not (msg Is Nothing) Then
                msg.Dispose()
            End If
        End Try

    End Sub

    Public Sub Send(ByVal msg As MailMessage)

        Dim smtp As SmtpClient

        Try
            smtp = New SmtpClient(Me.EmailServer)
            smtp.Send(msg)
        Catch ex As Exception
            Throw New ApplicationException("Error sending email.")
        End Try

    End Sub
Very fitting: http://xkcd.com/386/
Previous
Reply
Map
View

Click here to load this message in the networking platform