Link to home
Create AccountLog in
Avatar of spiraljonny
spiraljonny

asked on

SMTP Client - 'The SMTP host was not specified"

I am trying to send an email using the SMTPClient class but I keep getting the 'SMTP host was not specified error'. This is the code:
                    Dim smtpServer As SmtpClient
                    smtpServer = New SmtpClient()
                    smtpServer.Send(emailMessage)
                    smtpServer = Nothing
where emailMessage is an object of type MailMessage and is populated earlier in the function.
 
When I instantiate the object like this:
     smtpServer = New SmtpClient("our.host")
it works correctly.

As I understand it, the SMTPClient should obtain the host from the config file:
<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network host="our.host"/>
      </smtp>
    </mailSettings>
  </system.net>
</configuration>

The config file also contains system.diagnostic and runtime settings which I've left out for clarity.

Incidentally the framework is 2.0.

Any help would be much appreciated


Avatar of Aaron Jabamani
Aaron Jabamani
Flag of United Kingdom of Great Britain and Northern Ireland image

See Below link. Other better way I think is by adding the server name and other details in AppSettign section of the config file and reading them using configurationmanager.

http://forums.msdn.microsoft.com/en-US/csharpgeneral/thread/4ab25de2-4278-4d62-b2c1-c4dfc8975605/
ASKER CERTIFIED SOLUTION
Avatar of spiraljonny
spiraljonny

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer