Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Sending email to more than one address
Message
De
14/06/2007 09:44:51
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, États-Unis
 
 
À
14/06/2007 09:40:42
Jerry Tovar
Dana Corporation Dana It
Maumee, Ohio, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01232983
Message ID:
01232987
Vues:
10
>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/
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform