An Unrivaled Windows Hosting Experience
1-888-313-9421  | webteam@orcsweb.com
  1. Sending email from ASP.Net 4 - C# sample code

    (I updated the code sample based on feedback about C# naming standards and leveraging iDisposable - which I'm sure I'll forget many times until I get comfortable more with C#.)

    Below is sample code showing how to send email from ASP.Net 4 (currently in beta as of this posting) using C#. With this code I am assuming that the server already has a local SMTP service installed, so I use "localhost" to relay the email.

    Here is the SendMail.aspx page:

     

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SendMail.aspx.cs" Inherits="SendMail" %>

     

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

     

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head runat="server">

        <title></title>

    </head>

    <body>

        <form id="form1" runat="server">

        <div>

            Message to:

            <asp:TextBox ID="to" runat="server"></asp:TextBox>

            <br />

            Message from:

            <asp:TextBox ID="from" runat="server"></asp:TextBox>

            <br />

            Subject:

            <asp:TextBox ID="subject" runat="server"></asp:TextBox>

            <br />

            Message Body:

            <br />

            <asp:TextBox ID="body" runat="server" Height="171px" TextMode="MultiLine"

                Width="270px"></asp:TextBox>

            <br />

            <asp:Button ID="sendMail" runat="server" onclick="SendMail_Click"

                Text="Send Email" />

            <br />

            <br />

            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </div>

        </form>

    </body>

    </html>

     

    Here is the source code of the SendMail.aspx.cs page:

    using System;

    using System.Web.UI.WebControls;

    using System.Net.Mail;

     

    public partial class SendMail : System.Web.UI.Page

    {

        protected void SendMail_Click(object sender, EventArgs e)

        {

            using (MailMessage mailItem = new MailMessage(

                from.Text, to.Text, subject.Text, body.Text))

            {

                SmtpClient smtpServer = new SmtpClient("localhost");

                try

                {

                    smtpServer.Send(mailItem);

                }

                catch (Exception ex)

                {

                    Label1.Text = ex.ToString();

                }

            }

        }

    }

     

     

    Monday, February 08 2010 by | 0 comment(s)
    Tagged as: , , , , , ,

  2. How to install SMTP on Windows Server 2008

    The SMTP services are not installed by default on Windows Server 2008. To install that service, follow these steps...

    First go to the Features Summary section of the Server Manager and click Add Features.

    Server Manager Features Summary

    Then scroll down and select the SMTP Server option from the list.

    Once you click the SMTP Server option, you'll get a dialog box showing the other roles and features required for the SMTP service to work.

    Click Add Required Role Services then Next on the three subsequent dialog boxes. You're then presented with a summary and an Install button. Click Install and all the required services will be installed to support SMTP on the server.

     

    Thursday, February 04 2010 by | 0 comment(s)
    Tagged as: , , , ,

  3. Recent Spam Levels

    So much for the demise of McColo causing SPAM levels to drop by 75%. The level of spam as tracked by our devices for the most recent week ran right around 96%. That's right - only 4% of the email was legitimate email.

    Wednesday, December 03 2008 by | 0 comment(s)
    Tagged as: ,