一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達式|C/C++|IOS|C#|Swift|Android|VB|R語言|JavaScript|易語言|vb.net|

服務(wù)器之家 - 編程語言 - ASP.NET教程 - asp.net發(fā)郵件示例

asp.net發(fā)郵件示例

2019-12-03 11:58ASP.NET教程網(wǎng) ASP.NET教程

這篇文章主要介紹了asp.net發(fā)郵件示例,需要的朋友可以參考下

代碼如下:


protected void SendMail()
{
try
{
string CreaterName = "";
string examiner = "";
List<string> mailList = GetMailList(ref CreaterName, ref examiner);

 

MailEntity me = new MailEntity();
MailEntity me_1 = new MailEntity();

me.AddresserMail = ConfigurationManager.AppSettings["AddresserMail"].ToString();
me.AddresserName = ConfigurationManager.AppSettings["AddresserName"].ToString();
me.AddresserPwd = ConfigurationManager.AppSettings["AddresserPwd"].ToString();

me_1.AddresserMail = ConfigurationManager.AppSettings["AddresserMail_1"].ToString();
me_1.AddresserName = ConfigurationManager.AppSettings["AddresserName_1"].ToString();
me_1.AddresserPwd = ConfigurationManager.AppSettings["AddresserPwd_1"].ToString();

string strPostfix = ConfigurationManager.AppSettings["Postfix"].ToString();
string isSend = ConfigurationManager.AppSettings["isSend"].ToString();
StringBuilder ss = new StringBuilder();
if (isSend == "1")
{
if (mailList.Count > 0)
{
foreach (string mail in mailList)
{
int count = mail.IndexOf("@");
string postfix = mail.Substring(count + 1);

string[] pf = strPostfix.Split(new char[] { '|' });
int pCount = 0;
foreach (string p in pf)
{
if (postfix == p)
{
pCount++;
break;
}
}
if (pCount > 0)
{
me.AddresseeMail = mail.ToString();
}
else
{
me_1.AddresseeMail = mail.ToString();
}
string Body = "";

try
{
using (StreamReader sr = new StreamReader(HttpRuntime.BinDirectory + "/../tpl/tpl_Debt.htm", System.Text.Encoding.Default))
{
Body = sr.ReadToEnd();
}
}
catch (Exception ex)
{
lbMessage.Text = "*** 讀取模板出錯(reading template failed)!" + ex.Message;
lbMessage.ForeColor = System.Drawing.Color.Red;
return;
}

// --------------------------------------------------------------------------
me.ClientHost = ConfigurationManager.AppSettings["clientHost"].ToString();
me.MailEncoding = System.Text.Encoding.GetEncoding("GB2312");
me.MailPriority = System.Net.Mail.MailPriority.Normal;
me.IsBodyHtml = true;
me.Subject = "[" + CreaterName + "]創(chuàng)建的借款單";
//--------------------------------------------------------------------------
me_1.ClientHost = ConfigurationManager.AppSettings["clientHost_1"].ToString();
me_1.MailEncoding = System.Text.Encoding.GetEncoding("GB2312");
me_1.MailPriority = System.Net.Mail.MailPriority.Normal;
me_1.IsBodyHtml = true;
me_1.Subject = "[" + CreaterName + "]創(chuàng)建的借款單";

Body = Body.Replace("DTTPL_COMM_MODULE_NAME_ExpenseName", CreaterName);//借款人
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Type", ddlDebtType_Add.SelectedItem.Text);//借款類型
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Money", txbMoney_Add.Text);//金額
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Mender", txtMender.Text);//審核人
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Time", tbxDebtTime_Add.Text);//借款時間
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Advance", tbAdvance.Text);//代/墊款單位
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_DebtPathWay", ddlDebtPathWay.SelectedItem.Text);//借款方式
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Remark", txbMemo_Add.Text);//借款事由
// Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Mend", "");//審核意見
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_Memo", "");//備注
string url = HttpContext.Current.Request.Url.AbsoluteUri;
url = url.Replace("http://", "");
int index = url.IndexOf("/");
url = "http://" + url.Substring(0, index + 1);
Body = Body.Replace("DTTPL_COMM_MODULE_NAME_LINK", url + "Affair/SelectWorkEvent.aspx?typeid=249");


me.Body = Body;
me_1.Body = Body;

if (me.AddresseeMail == null && me.CopyToAddresseeMail == null && me_1.AddresseeMail == null && me_1.CopyToAddresseeMail == null)
{
lbMessage.Text = "*** 借款單保存成功! 但責任人/關(guān)注人因在數(shù)據(jù)庫沒有存郵箱地址,郵件未曾發(fā)送!";
lbMessage.ForeColor = System.Drawing.Color.Red;
return;
}
if (me.AddresseeMail != null || me.CopyToAddresseeMail != null)
{
bool temp = false;
for (int y = 0; y < 3; y++)
{
try
{
if (MailServer.SendMail(me))
{
temp = true;
break;
}
}
catch (Exception ex)
{
continue;
}

}
if (!temp)
{
if (me.AddresseeMail != null)
{
ss.Append(me.AddresseeMail.Trim());
}
if (me.CopyToAddresseeMail != null && me.CopyToAddresseeMail.Trim() != "")
{
ss.Append(",");
ss.Append(me.CopyToAddresseeMail.Trim());
}
}
me.AddresseeMail = null;
}
if (me_1.AddresseeMail != null || me_1.CopyToAddresseeMail != null)
{
bool temp = false;
for (int y = 0; y < 3; y++)
{
try
{
if (MailServer.SendMail(me_1))
{
temp = true;
break;
}
}
catch (Exception ex)
{
continue;
}
}
if (!temp)
{
if (ss.ToString().Trim() != "")
{
ss.Append(",");
if (me_1.AddresseeMail != null)
ss.Append(me_1.AddresseeMail.Trim());
if (me_1.CopyToAddresseeMail != null && me_1.CopyToAddresseeMail.Trim() != "")
{
ss.Append(",");
ss.Append(me_1.CopyToAddresseeMail.Trim());
}
}
else
{
if (me_1.AddresseeMail != null)
ss.Append(me_1.AddresseeMail.Trim());
if (me_1.CopyToAddresseeMail != null && me_1.CopyToAddresseeMail.Trim() != "")
{
ss.Append(",");
ss.Append(me_1.CopyToAddresseeMail.Trim());
}
}
}
me_1.AddresseeMail = null;
}
}
}
}
}
catch (Exception ex)
{
lbMessage.Text = "*** 發(fā)送失敗(the email is not sent)!" + ex.ToString();
lbMessage.ForeColor = System.Drawing.Color.Red;
}
}

 

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: h玉足嫩脚嗯啊白丝 | 亚洲冬月枫中文字幕在线看 | 午夜电影三级还珠格格 | 女人全身裸露无遮挡免费观看 | 国产欧美二区三区 | jizz中国jizz老师水多 | 99福利视频导航 | 国产视频一区 | 国产在视频线在精品 | 国产精品久久现线拍久青草 | 色吧五月婷婷 | 成成人看片在线 | 男人操美女视频 | 大乳奶水bbw | 91caoporm在线进入 | 亚州男人天堂 | 四虎国产精品免费入口 | freefron性中国国产高清 | 久久学生精品国产自在拍 | 国产高清视频一区二区 | 韩国理论三级在线观看视频 | 日本韩国无矿砖码 | 日本三级在丈面前被耍了 | 精品国产一二三区在线影院 | 亚洲乱码一二三四区国产 | 国产在线观看精品 | 国产一区二区三区在线观看视频 | 国产偷啪| 好男人好资源在线观看免费 | 欧美同性video | 男女福利视频 | 成人久久伊人精品伊人 | 亚洲首页国产精品丝袜 | 日本久久啪啪婷婷激情五月 | bt天堂在线最新版www | 国产精品主播在线 | 国产精品久久久久久久久久久搜索 | 日本javaajax| 女bbwxxxx非洲黑人 | 18亚洲chinese男男1069 | 国模丰满美女冰漪34d |