我试图使用下面的代码异步发送批量电子邮件。代码运行良好,可以发送电子邮件,但发送时未显示“发送电子邮件...”消息,并且btnCancel也不可见。有谁知道为什么??
Public Sub SendAsyncMail()
Dim mail As New MailMessage()
mail.From = New MailAddress("...")
mail.[To].Add(New MailAddress("..."))
mail.[To].Add(New MailAddress("..."))
mail.Subject = "Testing Email"
mail.Body = "..."
smtpClient.Credentials = New System.Net.NetworkCredential("...", "...")
smtpClient.Port = 587
smtpClient.Host = "smtp.gmail.com"
smtpClient.EnableSsl = True
Dim state As [Object] = mail
AddHandler smtpClient.SendCompleted, AddressOf smtpClient_SendCompleted
Try
smtpClient.SendAsync(mail, state)
lblMsg.Text = "Sending email..."
btnCancel.Visible = True
Catch ex As Exception
lblMsg.Text = ex.Message
End Try
答案 0 :(得分:1)
按钮未显示的事实是一个没有实际意义的事实。除非你把它留在某种延迟的队列中,否则他们无法取消发送该电子邮件。