Fire Hand
Fire Hand

Reputation: 26346

Send asynchronous email

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.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

Upvotes: 0

Views: 826

Answers (1)

ChaosPandion
ChaosPandion

Reputation: 78242

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.

Upvotes: 1

Related Questions