ASP.NET
  Home arrow ASP.NET arrow Page 4 - Sending Mail and Configuring Your Server f...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Sending Mail and Configuring Your Server for an ASP.NET 2.0 Email System
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-06-11

    Table of Contents:
  • Sending Mail and Configuring Your Server for an ASP.NET 2.0 Email System
  • Sending HTML Format Email
  • Sending Email with Attachments
  • Configuring Your Email Server

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sending Mail and Configuring Your Server for an ASP.NET 2.0 Email System - Configuring Your Email Server


    (Page 4 of 4 )

    Please note that here I'm going to show you a simple online e-mail sample system, so I'll only provide you with a few items to configure. Figure 2 shows the design time snapshot of the profile interface.

    Figure 2-the design time snapshot for configuring the system

    After the SystemProfile.aspx page has been initialized, the system displays the current configured information, such as information for the server IP, the mail server port, and so forth. This is done in the Page_Load function with the help of a helper function, BindWebMailProfile:

     

    protected void Page_Load(object sender,EventArgs e)

    {

      if(!Page.IsPostBack)

      { ///show the system configuration info

        BindWebMailProfile();

      }

    }

    private void BindWebMailProfile()

    { ///obtain the system configuration info

      IMail mail = new Mail();

      SqlDataReader dr = mail.GetWebMailProfile();

      if(dr.Read())

      {

        UserName.Text = dr["UserName"].ToString();

        AliasName.Text = dr["AliasName"].ToString();

        Email.Text = dr["Email"].ToString();

        IP.Text = dr["MailServerIP"].ToString();

        Port.Text = dr["MailServerPort"].ToString();

      }

      dr.Close();

    }

     

    Here, in the BindWebMailProfile function, we first create a new instance of the  Mail class, then call the GetWebMailProfile method of that class to obtain the configuration information from the SQL Server database. We then assign it to the corresponding fields on the page. Clicking the SetBtn button (i.e. OK) will trigger the SetBtn_Click event in which the newly-populated data are persisted back into the database. To do this, we've called the WebMailProfile method of the Mail class.

     

    protected void SetBtn_Click(object sender,EventArgs e)

    {

      try

      { ///define a new Mail object

        IMail mail = new Mail();

        ///execute the database operation

      mail.WebMailProfile(UserName.Text.Trim(),AliasName.Text.Trim(),
    Email.Text.Trim(),

          IP.Text.Trim(),Int32.Parse(Port.Text.Trim()));

        Response.Write("<script>alert('" + "The system has been configured
    successfully, please safekeep your data!" + "');</script>");

      }

      catch(Exception ex)

      { ///jump to the page dealing with exception handling

        Response.Redirect("ErrorPage.aspx?ErrorMsg=" + ex.Message.Replace
    ("<br>","").Replace("n","")

          + "&ErrorUrl=" + Request.Url.ToString().Replace("<br>","").Replace("n",""));

      }

    }

     

    Please check back tomorrow for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    ASP.NET ARTICLES

    - Advantages of the ASP.NET MVC Approach
    - ASP.NET Web Forms Weaknesses
    - ASP.NET Web Forms Meets ASP.NET MVC
    - Source Code for Saving and Retrieving Data w...
    - Using GridView to Save and Retrieve Data wit...
    - Handling Dynamic Images in ASP.NET 3.5 AJAX ...
    - Retrieving Data with AJAX and the GridView C...
    - Playing with Images in ASP.NET 3.5 AJAX Appl...
    - Saving and Retrieving Data with AJAX
    - Enhancing PHP Via the ASP.NET AJAX Framework...
    - Enhancing PHP Programming with the ASP.NET A...
    - Classes and ASP.NET AJAX
    - Using ASP.NET AJAX
    - Building a Simple Storefront with LINQ
    - Developing a Dice Game Using ASP.NET Futures...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
    Stay green...Green IT