Solved

SMTP Client - 'The SMTP host was not specified"

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sorting efficency of sorting algorithm 30 78
crm development 2 35
Converting C# Objects into JSON file 7 36
Create XML 5 30
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

14 Experts available now in Live!

Get 1:1 Help Now