By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Sending Emails

P: n/a
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
Jan 6 '08 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Jan 6, 5:40 pm, Guy Cohen <GuyCo...@discussions.microsoft.com>
wrote:
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.
Jan 6 '08 #2

P: n/a
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 ?

"kimiraikkonen" wrote:
On Jan 6, 5:40 pm, Guy Cohen <GuyCo...@discussions.microsoft.com>
wrote:
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.
Jan 6 '08 #3

P: n/a
On Jan 6, 6:35 pm, Guy Cohen <GuyCo...@discussions.microsoft.com>
wrote:
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 ?

"kimiraikkonen" wrote:
On Jan 6, 5:40 pm, Guy Cohen <GuyCo...@discussions.microsoft.com>
wrote:
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.
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.
Jan 6 '08 #4

P: n/a
On Jan 6, 6:44 pm, kimiraikkonen <kimiraikkone...@gmail.comwrote:
On Jan 6, 6:35 pm, Guy Cohen <GuyCo...@discussions.microsoft.com>
wrote:
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 ?
"kimiraikkonen" wrote:
On Jan 6, 5:40 pm, Guy Cohen <GuyCo...@discussions.microsoft.com>
wrote:
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.

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.
Jan 6 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.