0

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
3
  • try putting "smtpClient.SendAsync(mail, state)" after "btnCancel.Visible = True" Commented Feb 11, 2010 at 4:48
  • You aren't giving enough context for this question to really be answered. Commented Feb 11, 2010 at 4:49
  • I'm running a test on sending email asynchronously. So, the page would only have a send button, a cancel button, and a label. Once the send button is clicked, "Sending email..." message should be displayed and cancel button should be visible. But now, the message was not displayed and cancel button was not visible. Commented Feb 11, 2010 at 5:00

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.