problem sending email locally

hi EE,
I am not able to send an email locally using IIS.

The have the following code although I get 'unable to connect to the remote server".

Do you have any advise how to get this working?

The exception contains the following error message:

ex      {"Failure sending mail."}      System.Exception {System.Net.Mail.SmtpException}
+            [System.Net.Mail.SmtpException]      {"Failure sending mail."}      System.Net.Mail.SmtpException
+            Data      {System.Collections.ListDictionaryInternal}      System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
            HelpLink      null      string
+            InnerException      {"Unable to connect to the remote server"}      System.Exception {System.Net.WebException}
            Message      "Failure sending mail."      string
            Source      "System"      string
            StackTrace      "   at System.Net.Mail.SmtpClient.Send(MailMessage message)\r\n   at _Default.Page_Load(Object sender, EventArgs e) in c:\\WebSite1\\Default.aspx.cs:line 21"      string
+            TargetSite      {Void Send(System.Net.Mail.MailMessage)}      System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}

Many thanks,
            MailMessage message = new MailMessage();
            message.From = new MailAddress("");
            message.To.Add(new MailAddress(""));
            message.Subject = "Hello subject";
            message.Body = "The body";
            SmtpClient client = new SmtpClient("localhost");
        catch (Exception ex)


Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Amandeep Singh BhullarCommented:
You cannot send a mail from local iis unless mail server is configured
it says "Unable to connect to the remote server".
try doing the telnet to the mail server on smtp... (telnet mailserver port_number)
Is the relay enabled for this machine over the mail server? It has something to do with the connection to the mail server.

Let me know if you are stuck somewhere.
Ajay SharmaCommented:
Are you passing actual values instead of blablabla?

If yes, than here comes two conditions:
1) If local machine's IIS
     your mail server should be configured on your localhost or on active directory account

2) If you are using external domain's credentials.
    Here you must specify the smtp as and port number if required.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

jimbona27Author Commented:
How do I setup iis/ mail server to send emails from local
jimbona27Author Commented:
ajaysharmaapjs: how do I find out what port to use?  would it be mail.localhost?
if your mail server is on same machine then "user localhost" should be checked.

did you try doing so?
jimbona27Author Commented:
using windows server 2008 standard as the operating system.

any suggestions?
jimbona27Author Commented:
made that change now
jimbona27Author Commented:
i got this error message after making the change you suggested:

An exception of type 'System.Net.Mail.SmtpException' occurred in xx.Core.Messaging.DLL but was not handled in user code

Additional information: Error sending email: Mailbox unavailable. The server response was: 5.7.1 Unable to relay for

jimbona27Author Commented:
I have added this change to iis 6 as it has an option for SMTP virtual server #1..

now the code doesnt error when running in debug mode but I am yet to receive my first email...  
it means the send has happened successfully.....did you get any mail?
if not, now look into the mail box queue in the mail server. are there any mails in queue?
jimbona27Author Commented:
where is the mail box queue available?
inside the mail server.....

I presume here that u know the concept of mail server and mail box. Let me know if you need me to explain these terms as well.
jimbona27Author Commented:
yes explain.
jimbona27Author Commented:
please explain.
jimbona27Author Commented:
I can confirm the email is in my queue folder: C:\inetpub\mailroot\Queue
you are sending mail to
so this email is going to an address.....a box where all the email will be stored by that recipient. Thats your mail box.

Now, there can be many such mail boxes which will be housed inside the server....thats your mail server.
Mail server provides the various features for mail box management. eg. logs, queues, activity monitoring, relay, black listing etc.

when you send a mail, this has to be sent to the mail server. that mail will first reach mail box queue before landing in the mail box.

Now, as you see that the mail has reached the queue, It simple means that you have successfully sent it.
jimbona27Author Commented:
ok great, so how do I send the emails in my queued folder to the actual email address inbox?
there can be several reasons to it....

do you have norton firewall running on your system? can you stop the firewall and then try?

jimbona27Author Commented:
not that I can see.  
which mail server are you using? microsoft exchange?
jimbona27Author Commented:
im using windows server 2008 standard (SP2)..
I run the website in iis 7 although im not sure how it works but I also have iis 6 manager available and the smtp virtual server running.

im not sure what mail server im using...  where would this be?

I am talking about the destination mail box....smtp will send it to some detination mail box...where your mail box is located?
jimbona27Author Commented:
in the event viewer -> system I get the following message:

Message delivery to the host '' failed while delivering to the remote domain '' for the following reason: The remote server did not respond to a connection attempt.
jimbona27Author Commented:
my folders are located at: C:\inetpub\mailroot

my destination attempts include and

jimbona27Author Commented:
As I am working for a company I have even tried my email address at the company.

in the event viewer -> system I get the following message:

Message delivery to the host <IP> failed while delivering to the remote domain '' for the following reason: The remote server did not respond to a connection attempt.

jimbona27Author Commented:
just tried to used cmd.exe and typed

telnet <IP> 25

the message I get back is:

"connecting to <IP>... could not open connection to the host, on port 25: connection failed"

did this after reading:
jimbona27Author Commented:
any ideas?
what is that IP of? mail server?
also, try ping <IP>. if ping means that the port 25 is disabled at that server.
if ping does not work, then its a network problem between you system and that IP, you need to fix that.
jimbona27Author Commented:
IP is the website address, i.e.

I can ping the IP successfully.  

if I open IIS 6 manager, view properties of SMTP Virtual Server, then click 'Advanced' I have 'All Unassigned' with TCP Port being 25.  
jimbona27Author Commented:
i cannot open a cmd line telnet connection to my machine as I get this error:

"could not open connection to the host"

but you are not going to send that mail to this web site :)
keep IP that of the mail server, where you have a POP3 or IMAP enabled mail box.

first check where is the mail server and is it getting pinged and telnet-ed at port 25 or not.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jimbona27Author Commented:
I have telnet installed according to this window
jimbona27Author Commented:
ok, so if I telnet to my machine like the following that should answer whether I can use telnet or not..??  

When I try this I get 'connect failed'

jimbona27Author Commented:
i just got emails through..
great....where was the problem?
Though I saw you progressing through the issues till the last two posts, i have missed the link between your last two posts....thats why I was asking in my previous post.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.