📄 mailwebservice.cs
字号:
namespace PowerEasy.WebSite.Admin.Accessories
{
using PowerEasy.Enumerations;
using System;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Xml;
[ScriptService, WebService(Namespace="http://tempuri.org/"), WebServiceBinding(ConformsTo=WsiProfiles.BasicProfile1_1)]
public class MailWebService : WebService
{
[WebMethod]
public CommonMailServerConfig GetMailConfig(string txtMailFrom)
{
CommonMailServerConfig config = null;
Regex regex = new Regex(@"^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$");
if (regex.IsMatch(txtMailFrom))
{
config = new CommonMailServerConfig();
XmlDocument document = new XmlDocument();
document.Load(HttpContext.Current.Server.MapPath("~/Config/CommonMailServer.config"));
XmlNodeList list = document.SelectNodes("configuration/CommonMailServer/MailConfig");
if (list == null)
{
return config;
}
foreach (XmlNode node in list)
{
if (!(node.FirstChild.InnerText == txtMailFrom.Substring(txtMailFrom.IndexOf("@"))))
{
continue;
}
config.MailFrom = node.SelectSingleNode("MailFrom").InnerXml;
config.EnabledSsl = bool.Parse(node.SelectSingleNode("EnabledSsl").InnerXml);
config.Port = int.Parse(node.SelectSingleNode("Port").InnerXml);
config.MailServer = node.SelectSingleNode("MailServer").InnerXml;
string innerXml = node.SelectSingleNode("AuthenticationType").InnerXml;
if (innerXml == null)
{
goto Label_013F;
}
if (!(innerXml == "Basic"))
{
if (innerXml == "None")
{
goto Label_0136;
}
goto Label_013F;
}
config.AuthenticationType = AuthenticationType.Basic;
goto Label_0146;
Label_0136:
config.AuthenticationType = AuthenticationType.None;
goto Label_0146;
Label_013F:
config.AuthenticationType = AuthenticationType.Ntlm;
Label_0146:
config.MailServerUserName = node.SelectSingleNode("MailServerUserName").InnerXml.Replace("{$UserName}", txtMailFrom.Substring(0, txtMailFrom.IndexOf("@")));
return config;
}
}
return config;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -