M
Mark B
ASP 3.5 VB.NET website.
I call the following function on numerous webpages to send plain-text emails
where necessary.
All the pages however 'freeze' so to speak for the web user until the SMTP
is connected and the email sent.
How could I create a 'thread' in the following code that sends the email in
the background so my users don't have to wait (sometimes up to 30 seconds)
for the email to be sent before being taken to the success page? My webhost
doesn't allow me to use a pickup directory.
Public Function fSendMailPlainTextOnly( _
ByVal strTo As String, _
ByVal strFrom As String, _
ByVal strSubject As String, _
ByVal strBody As String, _
Optional ByVal strCC As String = "", _
Optional ByVal strBCC As String = "" _
) As String
fSendMailPlainTextOnly = ""
Dim cGeneral As New sfGeneral
'Send mail
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(strFrom)
mMailMessage.To.Add(New MailAddress(strTo))
If strBCC <> "" Then
mMailMessage.Bcc.Add(New MailAddress(strBCC))
End If
If strCC <> "" Then
mMailMessage.CC.Add(New MailAddress(strCC))
End If
mMailMessage.Subject = strSubject
mMailMessage.Body = strBody
Try
Dim mSmtpClient As New SmtpClient()
If Left(cGeneral.fGetConnectionString, Len("Data
Source=ME-VOSTRO\SQLEXPRESS")) = "Data Source=ME-VOSTRO\SQLEXPRESS" Then
mSmtpClient.Host = "smtp.myhost.com"
Dim SMTPUserInfo As New NetworkCredential("myusername",
"mypassword")
mSmtpClient.Credentials = SMTPUserInfo
mSmtpClient.Port = 587
Else
mSmtpClient.Host = "relay-hosting.godaddy-server.net"
End If
mSmtpClient.Send(mMailMessage)
fSendMailPlainTextOnly = "True"
Catch exc As Exception
fSendMailPlainTextOnly = "Email send failure: " + exc.ToString()
End Try
End Function
I call the following function on numerous webpages to send plain-text emails
where necessary.
All the pages however 'freeze' so to speak for the web user until the SMTP
is connected and the email sent.
How could I create a 'thread' in the following code that sends the email in
the background so my users don't have to wait (sometimes up to 30 seconds)
for the email to be sent before being taken to the success page? My webhost
doesn't allow me to use a pickup directory.
Public Function fSendMailPlainTextOnly( _
ByVal strTo As String, _
ByVal strFrom As String, _
ByVal strSubject As String, _
ByVal strBody As String, _
Optional ByVal strCC As String = "", _
Optional ByVal strBCC As String = "" _
) As String
fSendMailPlainTextOnly = ""
Dim cGeneral As New sfGeneral
'Send mail
Dim mMailMessage As New MailMessage()
mMailMessage.From = New MailAddress(strFrom)
mMailMessage.To.Add(New MailAddress(strTo))
If strBCC <> "" Then
mMailMessage.Bcc.Add(New MailAddress(strBCC))
End If
If strCC <> "" Then
mMailMessage.CC.Add(New MailAddress(strCC))
End If
mMailMessage.Subject = strSubject
mMailMessage.Body = strBody
Try
Dim mSmtpClient As New SmtpClient()
If Left(cGeneral.fGetConnectionString, Len("Data
Source=ME-VOSTRO\SQLEXPRESS")) = "Data Source=ME-VOSTRO\SQLEXPRESS" Then
mSmtpClient.Host = "smtp.myhost.com"
Dim SMTPUserInfo As New NetworkCredential("myusername",
"mypassword")
mSmtpClient.Credentials = SMTPUserInfo
mSmtpClient.Port = 587
Else
mSmtpClient.Host = "relay-hosting.godaddy-server.net"
End If
mSmtpClient.Send(mMailMessage)
fSendMailPlainTextOnly = "True"
Catch exc As Exception
fSendMailPlainTextOnly = "Email send failure: " + exc.ToString()
End Try
End Function