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. |