Solved

SMTP Client - 'The SMTP host was not specified"

Posted on 2008-06-12
2
4,897 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now