开发者

Send asynchronous email

开发者 https://www.devze.com 2022-12-20 07:17 出处:网络
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 btnCanc

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消