以密件抄送方式向多个用户发送电子邮件

时间:2011-12-15 13:12:29

标签: asp.net vb.net

我正在开发一个项目,我将向多个用户发送电子邮件,如下所示

 Dim users(20) As String

        users(0) = "xx@example.com"
        users(1) ="xx@xexample.com"
        users(2) = "xx@example.com"
        users(3) = "xx@example.com"
        users(4) = "xx@example.com"
        users(5) = "xx@example.com"
        users(6) = "xx@example.com"
        users(7) = "xx@example.com"
        users(8) = "xx@example.com"
        users(9) = "xx@example.com"
        users(10) = "xx@example.com"


   For i = 0 To 10
        em.Bcc.Add(users(i))
       or
          em.Bcc.Add(New MailAddress (users(i)))

        Next

        mailClient.Send(em)

但它只向一位我尝试过的用户发送电子邮件

 Dim sendto As String
        sendto = Nothing

        For i = 0 To 10
           sendto = sendto + users(i) + ","
        Next
  em.Bcc.Add(sendto)

仍然无法解决代码中出现的问题 我正在使用asp.net和vb。

1 个答案:

答案 0 :(得分:1)

您的代码应该更像这样:

Sub SendToMany()
    'create the mail message
    Dim mail As New MailMessage()

    mail.From = New MailAddress("me@mycompany.com", "Ashok P")

    mail.To.Add("you@yourcompany.com")

    mail.Bcc.Add("blindcc1@yourcompany.com")
    mail.Bcc.Add("blindcc2@yourcompany.com")

    'set the content
    mail.Subject = "This is an email"
    mail.Body = "this is the body content of the email."

    'send the message
    Dim smtp As New SmtpClient(youmailserver) 'dont forget to include username/password via networkcredentials 
    smtp.Send(mail)
End Sub 'MultipleRecipients
相关问题