Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SMTP Client - 'The SMTP host was not specified"

Posted on 2008-06-12
2
Medium Priority
?
4,930 Views
Last Modified: 2013-11-26
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


0
Comment
Question by:spiraljonny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Expert Comment

by:apeter
ID: 21770633
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/
0
 

Accepted Solution

by:
spiraljonny earned 0 total points
ID: 21777191
I tried the workaround, but putting the host into the appSettings section didn't work. I deleted the config file and created a new config file without the system.diagnostics and now it works correctly.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question