Feedback-Mail (database is XML)

Source: Internet
Author: User
Tags object mail tostring mailmessage
xml| Data | The database website or the enterprise has many problems, then each guest consultation problem is not a department all can serve well, so the network out of this thing, an opinion or advice or consultation, as long as the choice of different departments, the message sent to different departments;
Following this rule, I did a little example based on XML and email, because it was not complicated, so I just posted the code!

The page code is as follows


Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
The following two are the newly introduced namespaces, 1 are mail, 2 is IO
Using System.Web.Mail;
Using System.IO;

Namespace Mation
{
/**////<summary>
Summary description of the WebForm1.
</summary>
public class WebForm1:System.Web.UI.Page
{
protected System.Web.UI.WebControls.DropDownList DropDownList1;
protected System.Web.UI.WebControls.TextBox Textbox4;
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.HtmlControls.HtmlTable Table1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load (object sender, System.EventArgs e)
{
FileStream fs=new FileStream (Server.MapPath ("Db.xml"), filemode.open,fileaccess.read);//Create Text stream
StreamReader sr=new StreamReader (FS);//Create Reader
DataSet Ds=new DataSet ()//Declare a local surface
Ds. READXML (SR);//load content into local table
This. Dropdownlist1.datasource=ds. tables[0];//Set Data source
This. Dropdownlist1.datatextfield= "bumen";//Set the text field displayed
This. dropdownlist1.datavaluefield= "addr";//corresponding value
This. Dropdownlist1.databind ()//Binding
}

This is the code generated by the form designer

private void Button1_Click (object sender, System.EventArgs e)
{
Create message text
String the= "new message <br> Name:" +textbox1.text.tostring () + "<br> Email address:" +textbox2.text.tostring () + "<br> Opinion is: "+textbox3.text.tostring ();//Construct Message body content
Response.Write (The);
MailMessage mm=new MailMessage ();//Instantiate an email object
Mm. From=textbox2.text.tostring ()//return address of Sender
Mm. To=this. dropdownlist1.selecteditem.value;//address of the addressee, which is the destination of the message
Mm. Subject=this. Textbox4.Text.ToString ()//message header
Mm. body=the;//message body
Smtpmail.send (mm);//Send
This. table1.visible=false;//Hidden table
This. Label1.text= "Your mail has been sent out!" ";//display a hint message

}
}
}

The following is the XML file code


1<?xml version= "1.0" encoding= "Utf-8"?>
2<newdataset>
3 <email>
4 <id>1</id>
5 <bumen> website Business Department </bumen>
6 <addr>thcjp@126.com</addr>
7 </email>
8 <email>
9 <id>2</id>
<bumen> Sales Department </bumen>
<addr>xx@xxx.xx</addr>
</email>
<email>
<id>3</id>
<bumen> Quality Supervision Department </bumen>
<addr>zz@xxx.com</addr>
</email>
<email>
<id>4</id>
<bumen> Finance Department </bumen>
<addr>cw@xxx.com</addr>
</email>
<email>
<id>5</id>
<bumen> Day Wear </bumen>
Num <addr>110535808@qq.com</addr>
</email>
28</newdataset>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.