0

In ASP.NET Unleashed book (SAMS Publishing, http://www.informit.com/store/asp.net-4-unleashed-9780672331121 ISBN-10: 0-13-256581-1 ) have a snippet: File: SendMail.aspx:

<%@ Page Language="C#" %>

<%@ Import Namespace="System.Net.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    void Page_Load()
    {
        SmtpClient client = new SmtpClient();
        client.Host = "localhost";
        client.Port = 25;
        client.Send("nate@somewhere", "[email protected]",
        "Beware!", "Watch out for zombies!");
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Send Mail</title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            Email sent!
        </div>
    </form>
</body>
</html>

The book warning: "...sends the email by using the local SMTP Server. If your SMTP Server is not enabled, you receive the error An Existing Connection Was Forcibly Closed by the Remote Host. You can enable your local SMTP Server by opening Internet Information Services, right-clicking Default SMTP Virtual Server, and selecting Start."

By using Visual Sutio 2012, include built-in IIS Express, I can not practice this code, because IIS Express don't support SMTP.

Please help me change IIS Express to full function IIS to practice below snippet.

4
  • Why not just send to your ISP/Mail provider's SMTP server?
    – spender
    Aug 3, 2013 at 14:01
  • I am sorry, I don't understand your question fully. Email address in below snippet is sample... I try to send mail (or fake mail) using localhost. Aug 3, 2013 at 14:10
  • Why use localhost? Did you want to set up a mail server? It's trivial to obtain your mail provider's SMTP and to use that instead. If not, install IIS and change your project settings to use IIS instead of the dev webserver.
    – spender
    Aug 3, 2013 at 14:15
  • Thank @spender, Please show me how to "change your project settings to use IIS instead of the dev webserver" step by step. Aug 3, 2013 at 14:25

2 Answers 2

0

OK. So you installed IIS after .Net, so make sure that you've run aspnet_regiis.exe.

Now, right click your project, choose properties and follow these instructions from Microsoft.

0

IIS Express is a version on Home/Family editions, not professional/Ultimate. If you don't have a Windows Pro/Ultimate you can install your own SMTP server, there are plenty of free good ones on the Web.

But if you don't want to lost time to instal/configure an SMTP server for testing emails you can directly send emails from the .Net Framework.

4
  • I am using Window 8 Pro, Visual Studio 2012 Ultimate. I go to Add and Remove Program Control Panel, and Add IIS serive to Windows 8 operating system. But I cannot put file FirstPage.aspx to C:\inetpub\wwwroot for testing, because Visual Studio don't compile my aspx file. Aug 3, 2013 at 14:13
  • @tranvana: .aspx files aren't compiled by VS. They're compiled on first load/change by the .net hosting environment (IIS).
    – spender
    Aug 3, 2013 at 14:14
  • I try to put FirstPage.aspx to C:\inetpub\wwwroot , then run: localhost/FirstPage.aspx, but error: "HTTP Error 404.3 - Not Found The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map." Aug 3, 2013 at 14:17
  • @tranvana: codesnob.wordpress.com/2010/12/23/installing-iis-after-net-4 probably applies to you because you installed IIS after .net.
    – spender
    Aug 3, 2013 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.