[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
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
Re: Problems with System.Net.Mail
Thank you. I got it now :)