Sending Emails

  • Thread starter Thread starter Guy Cohen
  • Start date Start date
G

Guy Cohen

Hi all
I use:
Dim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text,
txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)

And its working fine.
However I was wondering if there is a way to confirm that the email was sent.
The send method does not return anything....

Please advise

TIA
Guy Cohen
 
Hi all
I use:
Dim message As New MailMessage(txtTo.Text, txtFrom.Text, txtSubject.Text,
txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)

And its working fine.
However I was wondering if there is a way to confirm that the email was sent.
The send method does not return anything....

Please advise

TIA
Guy Cohen

After "emailclient.send" you add a messagebox which confirms success,
that's all. I've done like that and works.

Like:
Try
Dim message As New MailMessage(txtTo.Text, txtFrom.Text,
txtSubject.Text,
txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)
msgbox("successfully sent")

Catch ex as exception
Msgbox(ex.message)

end try

You can test, enter some invalid SMTP server address then you will get
a error in msgbox(ex.message) which is defined inside catch method
saying with "failure sending mail"

Hope this helps.

Let us know

Regards.
 
In other words - you say if "on error" or "try/catch" did not trap any error
it means - it is ok?
....Can someone approve that ?
 
In other words - you say if "on error" or "try/catch" did not trap any error
it means - it is ok?
...Can someone approve that ?
Hi,
Have you tried the code?
I tried the code with entering an invalid SMTP code.

when it fails because of invalid smtp address you get "failure sending
mail" in a messagebox. Even there may be different reason of errors,
but i'm afraid .NET's mail send feature doesn't report the failure
reason. Just says "failure sending mail"
Catch ex as exception
Msgbox(ex.exception)

If there's no problem you get what you set as a success notification.
In this case you can use messagebox:

Try
Dim message As New MailMessage(txtTo.Text, txtFrom.Text,
txtSubject.Text,
txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)
msgbox("successfully sent")

Catch ex as exception
Msgbox(ex.message)

end try

Thanks.
 
Hi,
Have you tried the code?
I tried the code with entering an invalid SMTP code.

when it fails because of invalid smtp address you get "failure sending
mail" in a messagebox. Even there may be different reason of errors,
but i'm afraid .NET's mail send feature doesn't report the failure
reason. Just says "failure sending mail"
Catch ex as exception
Msgbox(ex.exception)

If there's no problem you get what you set as a success notification.
In this case you can use messagebox:

Try
Dim message As New MailMessage(txtTo.Text, txtFrom.Text,
txtSubject.Text,
txtBody.Text)
Dim emailClient As New SmtpClient(txtSMTPServer.Text)
emailClient.Send(message)
msgbox("successfully sent")

Catch ex as exception
Msgbox(ex.message)

end try

Thanks.

Addition: Catch block also reports some other errors such as invalid
sender mail or destination mail like some strings but "before"
sending. As you know, after sending mail with correct standards(smtp
server name, correct form of mail address) there's no guarantee that
the destination address will be found on destination server, you may
get a returning failure mail from destination server if destination
mail address is unreachable due to any reason on server-side. It's
about regular mailing stragegy not about .NET's mail feature of
course.

Regards.
 
Back
Top