|
-
Sep 28th, 2009, 09:43 AM
#1
Thread Starter
New Member
[RESOLVED] Problems with System.Net.Mail
Hello.
When I use the code below to send an e-mail from my form, the mail is not sent before the program is closed...
Anybody have any idea why this is so?!
Code:
'create the mail message
Dim mail As New MailMessage
'set the addresses
mail.From = New MailAddress("[email protected]")
mail.To.Add("[email protected]")
'set the content
mail.Subject = "Mail Subject here."
mail.Body = "Mail body here."
mail.IsBodyHtml = False
'send the message
Dim smtp As New SmtpClient("YOUR SMTP SERVER")
smtp.Credentials = New System.Net.NetworkCredential("Username", "Password")
Try
smtp.Send(mail)
Finally
mail.Dispose()
smtp = Nothing
End Try
-
Sep 28th, 2009, 09:48 AM
#2
Re: Problems with System.Net.Mail
Add a Catch block to your Try block and then you can actually see what the error is that is undoubtedly being thrown and is currently hidden from you... Alternatively, while you are still writing the program like this then you could just remove the Try block altogether so that any exceptions are thrown in the debugger and you can easily look at all of the information available with the exception
EDIT: Actually it seems I was wrong, your current code should still actually throw exceptions. However, just to be sure, if you stick a Catch block in there then do you get any exceptions thrown? For example:
Code:
Try
smtp.Send(mail)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
mail.Dispose()
smtp = Nothing
End Try
Last edited by chris128; Sep 28th, 2009 at 09:57 AM.
-
Sep 28th, 2009, 12:24 PM
#3
Thread Starter
New Member
Re: Problems with System.Net.Mail
Thank you. I got it now
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|