为什么我的SmtpServer.Send代码发送多个电子邮件副本?

时间:2012-01-20 03:32:28

标签: vb.net

每当调用发送电子邮件功能时,收件人将同时收到三封相同的电子邮件。我检查了编码,我找不到这种情况的原因。电子邮件可以成功发送,但我只想收到一封电子邮件,而不是三封。这是代码:

Private Sub SendEmail(ByVal item_no As String)
    Dim recipient() As String
    recipient = New String() {"user1@company.com", _
                              "user2@company.com", _
                              "user3@company.com", _
                              "user4@company.com"}

    Dim carboncopy() As String
    carboncopy = New String() {"myuser1@company.com", _
                               "myuser2@company.com", _
                               "myuser3@company.com", _
                               "myuser4@company.com"}

    Dim SmtpServer As New SmtpClient()
    Dim mail As New MailMessage()

    SmtpServer.Credentials = New  _
    Net.NetworkCredential("sender@company.com", "")
    SmtpServer.Port = 25
    SmtpServer.Host = "SmtpServer"

    mail = New MailMessage()
    mail.From = New MailAddress("sender@company.com")

    For i As Integer = 0 To recipient.Length - 1
        mail.To.Add(recipient(i))
    Next

    For i As Integer = 0 To carboncopy.Length - 1
        mail.CC.Add(carboncopy(i))
    Next

    mail.Subject = "Item No. " & item_no

    mail.Body = "Hi" & vbCrLf & vbCrLf & _
    "To Whom May Concern," & vbCrLf & _
    "Please provide the new instruction for item no. " & item_no & "."

    Try
        SmtpServer.Send(mail)
        SmtpServer = Nothing

    Catch ex As Exception
        lblError.Text = ex.ToString
        Exit Sub

    End Try
End sub

0 个答案:

没有答案