Determine if an email message was sent
I am creating a webform to send an email message using the System.Web.Mail Namespace. When the user clicks the submit button and the message is actually sent I want to redirect them to a confirmation page letting them know the message was sent succesfly.
How can I determine if the message was sent succesfly.
Here is the code I have so far
Code:
Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If (Page.IsValid) Then
Dim newMail As New MailMessage
Try
newMail.From = txtSendersEmailAddress.Text
newMail.From = txtSenderName.Text
newMail.Subject = ddlQueryType.SelectedValue + " " + txtSubject.Text
newMail.To = "[email protected]"
newMail.BodyFormat = MailFormat.Text
newMail.Body = newMail.From + newMail.Subject + txtMessage.Text
SmtpMail.SmtpServer = "your.smtpserver.net.net"
SmtpMail.Send(newMail)
Catch ex As Exception
Finally
newMail = Nothing
End Try
End If
Re: Determine if an email message was sent
if the email send fails... an exception should be thrown... so if you check for the exception (which you are doing) then you should be able to vary the output page from pass or fail simply by catching the error...
you may want to look at the MailMessage object on MSDN to see any specific errors it might throw if you want to determine the cause of the failure...
Re: Determine if an email message was sent
Is it possible to send a request for receipt of email using the MailMessage object?