I was trying to send bulk email asynchronously using the code below. The code works well, email was able to be sent but the "Sending email..." message was not displayed while sending and the btnCancel was not visible as well. Does anyone knows why??
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.SendComplet开发者_开发问答ed, 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
The fact that the button is not being displayed is a moot point. They will not be able to cancel sending that e-mail anyway unless you keep it in some sort of delayed queue.
精彩评论