David C
asked on
No difference with ASP.NET asynchronous email
Hi, I was making some upgrades to my code for emails to be sent asynchronously however I notice there is no difference in the delay after the user click s the send button.
This is the normal code
This is the new asynchronous method;
Any ideas?
This is the normal code
Dim mail As New MailMessage()
mail.From = New MailAddress(Label9.Text)
mail.To.Add(Label9.Text)
'set the content
mail.Subject = "Normal"
mail.IsBodyHtml = True
'send the message
Dim smtp As New SmtpClient("smtpserver") '
smtp.Send(mail)
This is the new asynchronous method;
Dim mailMessage As New System.Net.Mail.MailMessage
mailMessage.From = New MailAddress(Label9.Text)
mailMessage.To.Add("itsupport@seabrookcrisps.com")
mailMessage.Subject = "Async Email"
mailMessage.IsBodyHtml = True
mailMessage.Body = "Test"
Dim smtpClient As New SmtpClient()
Dim userState As Object = mailMessage
'Attach event handler for async callback
AddHandler smtpClient.SendCompleted, AddressOf SmtpClient_OnCompleted
Try
'Send the email asynchronously
smtpClient.SendAsync(mailMessage, userState)
Catch smtpEx As SmtpException
'Error handling here
Catch ex As Exception
'Error handling here
End Try
Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER