0

我正在尝试一次向多个人发送邮件。

我的代码是这样的;

 Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("jasibs002@gmail.com", "someMadeUpPassword")
            SmtpServer.Port = 25
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.EnableSsl = True
            Dim omail As New MailMessage()

        omail.From = New MailAddress("jasibs002@gmail.com", "JaseemBinBacker", System.Text.Encoding.UTF8)

        omail.Subject = "Test Mail"
        Dim str As String
        str = "Hai How Are You I am Sendig This Mail for Testing"
        str = str + vbNewLine & "Checking"
        str = str + vbNewLine & "Sucess"
        omail.Body = str
        Dim email As String
        Dim cmdemail As New SqlCommand("SELECT Emailid FROM  dbo.Email_tbl", con.connect)
        dr = cmdemail.ExecuteReader
        While dr.Read
            email = dr("Emailid")
            omail.To.Add(email)

        End While
        dr.Close()
        con.disconnect()
     SmtpServer.SendAsync(omail, Nothing)

    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try

执行此操作时,出现以下错误; An asynchronous call is already in progress. It must be completed or canceled before you can call this method.

我的电子邮件Table有 10 多个电子邮件 ID。

4

1 回答 1

2

将您的 While 循环更改为:

    While dr.Read
        email = dr("Emailid")
        omail.To.Add(email)

    End While
    SmtpServer.SendAsync(omail, Nothing)
于 2013-08-14T12:29:41.583 回答