Using SMTP

Christopherx

Well-known member
Joined
Jul 4, 2010
Messages
58
Programming Experience
Beginner
Sub Main()
Try
Dim mail As New MailMessage
Dim client As New SmtpClient
client.Host = "192.168.0.4"
client.Port = 80
mail.To.Add("chris_cooney@hotmail.co.uk")
mail.From = New MailAddress("chris_cooney@hotmail.co.uk")
mail.Body = "Just testing mate. juuuust testing"
client.Send(mail)
Console.WriteLine("happy days!")
Console.ReadKey()
Catch e As Exception
Console.WriteLine(e.Message)
Console.ReadKey()
End Try

I get an error that simply states.. "Failure sending mail".
Any suggestions ?
 
Last edited:
What was the exception type? I would have guessed, but happen to know, that it was a SmtpException, indicating error in relation to Smtp server. When catching exceptions catch specific one's and not the base Exception. Specific exceptions has specific cause and possibly remedy. Catch only exceptions that you know you can identify and handle. SmtpClient.Send method lists the specific exception it may throw and the reasons they may happen. In either case your attempt to send would ultimately result in 'failure' when there is any problem, but from there your app can give better feedback about what the problem was.

Do you have a Smtp server at that address and port? The ip could be right (in local network), but the port 80 rather unusual as it's the default http protocol port (where browser connect to request web pages). This would also explain why you didn't get an error stating Smtp server problem rather than generic 'Failure', since that ip/port would likely connect though with invalid service. As help for Port property explains the default Smtp protocol port is 25, though the service could be configured for any port really, you just have the ask the admin running the service.
 
I'm completely unfamiliar with the processes involved in smtp, so I just put in my IP address in the hopes that would work! Rookie mistake i guess! Anyhow, do you know of any ip-addresses I can use ? I changed the port to 25 after some research, the only issue is finding the smtp server!
 
Your ISP usually provides an email account and the Smtp server details for using it.
 
You probably received a paper with this information, if not contact them.
 
open your mail client and look at the account settings. You can also log into your Sky account on the web and get settings for that sort of thing. If you use hotmail, as your post suggests, a quick google for hotmail SMTP settings brings something like this: Hotmail POP3 and SMTP Settings
 
Back
Top