惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

www.infosecurity-magazine.com
www.infosecurity-magazine.com
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
Cloudbric
Cloudbric
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
S
Schneier on Security
L
LangChain Blog
Jina AI
Jina AI
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
T
Tenable Blog
B
Blog RSS Feed
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
W
WeLiveSecurity
I
InfoQ
The Hacker News
The Hacker News
雷峰网
雷峰网
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
Hacker News: Ask HN
Hacker News: Ask HN
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
人人都是产品经理
人人都是产品经理
V
V2EX
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cybersecurity and Infrastructure Security Agency CISA
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
阮一峰的网络日志
阮一峰的网络日志
SecWiki News
SecWiki News
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - Leon0812

Export csv Export Excel Jquery pluign development example Resource file management Excel Reader iframe 中显示内嵌页的局部 - Leon0812 - 博客园 easyslider - Leon0812 - 博客园 缩放页面字体 可编辑DIV - Leon0812 - 博客园 vs快捷键大全(转) SQL文件執行 利用IHttpModule、IHttpHandler做授权类 - Leon0812 - 博客园 C#调用非托管的DLL 无缝滚动 - Leon0812 - 博客园 获取-编译-打包 VS作业一条龙批处理 Reporting Service for SQL 2008匿名访问报表方法 獲取控件位置 - Leon0812 - 博客园 Installscript中修改web.config - Leon0812 - 博客园 publish
XML Mail Template Management
Leon0812 · 2011-09-01 · via 博客园 - Leon0812

XML:

<?xml version="1.0" encoding="utf-8"?>
<mail>
<smtp from="yyc_163@163.com" pwd="ixafhp" fromName="Ricoh" cc="youcai@chinasoftware.eu" needPWD="1">
<network host="smtp.163.com" port="25" />
<validfield>
{ProductType},{InvoiceNumber},{Name},{Address},{Postcode},{City},{Email},{Note},{Status},{CreateDate}
</validfield>
</smtp>
<acceptmail>
<subject>Accept Mail</subject>
<body>Dear Customer,
This is a Accept Mail.

{ProductType},
{InvoiceNumber},
{Name},
{Address},
{Postcode},
{City},
{Email},
{Note},
{Status},
{CreateDate}

</body>
</acceptmail>
<rejectmail>
<subject>Reject Mail</subject>
<body>Dear Customer,
This is a reject Mail.

{ProductType},
{InvoiceNumber},
{Name},
{Address},
{Postcode},
{City},
{Email},
{Note},
{Status},
{CreateDate}

</body>
</rejectmail>
</mail>

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;public partial class Admin_MailTemplate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindMailTemplate();
}
}
private void BindMailTemplate()
{
string filePath = HttpContext.Current.Server.MapPath("~/Config/MailTemplate.xml");
XmlDocument xmlDoc
= new XmlDocument();
xmlDoc.Load(filePath);
XmlNode node
= xmlDoc.SelectSingleNode("mail");string from = node["smtp"].Attributes["from"].Value;
string pwd = node["smtp"].Attributes["pwd"].Value;
string needPWD = node["smtp"].Attributes["needPWD"].Value;
string fromName = node["smtp"].Attributes["fromName"].Value;
string cc = node["smtp"].Attributes["cc"].Value;string host = node["smtp"]["network"].Attributes["host"].Value;
string hostPort = node["smtp"]["network"].Attributes["port"].Value;
string validField = node["smtp"]["validfield"].InnerText;string subjectAccept = node["acceptmail"]["subject"].InnerText;
string bodyAccept = node["acceptmail"]["body"].InnerText;string subjectReject = node["rejectmail"]["subject"].InnerText;
string bodyReject = node["rejectmail"]["body"].InnerText;this.txtFrom.Text = from;
this.txtPassword.Text = pwd;
this.txtPassword.Attributes.Add("value", pwd);
this.cbxNeedPWD.Checked = needPWD == "1" ? true : false;
this.txtFromName.Text = fromName;
this.txtCopyTo.Text = cc;
this.txtHost.Text = host;
this.txtPort.Text = hostPort;
this.txtAcceptSubject.Text = subjectAccept;
this.txtAcceptBody.Text = bodyAccept;
this.txtRejectSubject.Text = subjectReject;
this.txtRejectBody.Text = bodyReject;
this.txtValidFild.Text = validField;

}

protected void btnSave_Click(object sender, EventArgs e)
{
try
{
string filePath = HttpContext.Current.Server.MapPath("~/Config/MailTemplate.xml");
XmlDocument xmlDoc
= new XmlDocument();
xmlDoc.Load(filePath);
XmlNode node
= xmlDoc.SelectSingleNode("mail");

node[

"smtp"].Attributes["from"].Value = this.txtFrom.Text;
node[
"smtp"].Attributes["fromName"].Value = this.txtFromName.Text;
node[
"smtp"].Attributes["cc"].Value = this.txtCopyTo.Text;
node[
"smtp"].Attributes["needPWD"].Value = this.cbxNeedPWD.Checked ? "1" : "0";

node[

"smtp"]["network"].Attributes["host"].Value = this.txtHost.Text;
node[
"smtp"]["network"].Attributes["port"].Value = this.txtPort.Text;

node[

"acceptmail"]["subject"].InnerText = this.txtAcceptSubject.Text;
node[
"acceptmail"]["body"].InnerText = this.txtAcceptBody.Text;

node[

"rejectmail"]["subject"].InnerText = this.txtRejectSubject.Text;
node[
"rejectmail"]["body"].InnerText = this.txtRejectBody.Text;if (!string.IsNullOrEmpty(this.txtPassword.Text))
{
node[
"smtp"].Attributes["pwd"].Value = this.txtPassword.Text;
}
xmlDoc.Save(filePath);
this.Message1.ShowInfo("Save successfully!");
//Response.Write("<script>alert('geslaagd');window.location='MailTemplate.aspx';</script>");
}
catch(Exception ex)
{
this.Message1.ShowError("Fail to save!<br/>" + ex.Message.Replace("'", ""));
//Response.Write("<script>alert('niet'" + ex.Message.Replace("'", "") + ");history.back(-1)</script>");
}
}
}

HTML:

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/BackPage.master" ValidateRequest="false" AutoEventWireup="true" CodeFile="MailTemplate.aspx.cs" Inherits="Admin_MailTemplate" %><%@ Register src="Navigator.ascx" tagname="Navigator" tagprefix="uc1" %><%@ Register src="Message.ascx" tagname="Message" tagprefix="uc2" %><asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"><uc1:Navigator ID="Navigator1" runat="server" />
<uc2:Message ID="Message1" runat="server" />
<table style="background-color:#BFE7F6; width:100%;" >
<tr>
<td style="width:100px">Host:</td> <td> <asp:TextBox ID="txtHost" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Port:</td> <td> <asp:TextBox ID="txtPort" runat="server" onchange="if(/\D/.test(value))value=value.replace(/\D/g,'')" ></asp:TextBox></td>
</tr>
<tr>
<td>From:</td> <td> <asp:TextBox ID="txtFrom" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>FromName:</td> <td> <asp:TextBox ID="txtFromName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Need Password:</td> <td> <asp:CheckBox ID="cbxNeedPWD" runat="server" /></td>
</tr>
<tr>
<td>Password:</td> <td> <asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td>CopyTo:</td> <td> <asp:TextBox ID="txtCopyTo" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Valid Fields:</td> <td> <asp:Label ID="txtValidFild" runat="server" ReadOnly="true" style="width:600px"></asp:Label></td>
</tr>
<tr>
<td colspan="2" style="background-color:#49BEEB; ">Accept Mail</td>
</tr>
<tr>
<td>Subject:</td> <td> <asp:TextBox ID="txtAcceptSubject" runat="server" style="width:600px"></asp:TextBox></td>
</tr>
<tr>
<td>Body:</td> <td> <asp:TextBox ID="txtAcceptBody" runat="server" TextMode="MultiLine" Rows="10" style="width:600px"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="background-color:#49BEEB; ">Reject Mail</td>
</tr>
<tr>
<td>Subject:</td> <td> <asp:TextBox ID="txtRejectSubject" runat="server" style="width:600px"></asp:TextBox></td>
</tr>
<tr>
<td>Body:</td> <td> <asp:TextBox ID="txtRejectBody" runat="server" TextMode="MultiLine" Rows="10" style="width:600px"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2"><asp:Button ID="btnSave" runat="server" Text="Save"
onclick
="btnSave_Click" /> </td>
</tr></table>
</asp:Content>