Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The compiling method of sending E-mail with asp.net

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "the method of sending email with asp.net". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "the method of writing email with asp.net".

The copy code is as follows:

Protected void SendMail ()

{

Try

{

String CreaterName = ""

String examiner = ""

List 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 = "* error reading template (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 + "] created loan order"

/ /-

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 + "] created loan order"

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_ExpenseName", CreaterName); / / borrower

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Type", ddlDebtType_Add.SelectedItem.Text); / / loan type

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Money", txbMoney_Add.Text); / / amount

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Mender", txtMender.Text); / / auditor

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Time", tbxDebtTime_Add.Text); / / loan time

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Advance", tbAdvance.Text); / / Agent / advance unit

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_DebtPathWay", ddlDebtPathWay.SelectedItem.Text); / / loan method

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Remark", txbMemo_Add.Text); / / loan reason

/ / Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Mend", ""); / / Review opinion

Body = Body.Replace ("DTTPL_COMM_MODULE_NAME_Memo", ""); / / remarks

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 = "* the loan slip was saved successfully! however, the email has not been sent because the responsible person / follower does not have an email address in the database!"

LbMessage.ForeColor = System.Drawing.Color.Red

Return

}

If (me.AddresseeMail! = null | | me.CopyToAddresseeMail! = null)

{

Bool temp = false

For (int y = 0; y < 3; yearly +)

{

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; yearly +)

{

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 = "* failed to send (the email is not sent)!" + ex.ToString ()

LbMessage.ForeColor = System.Drawing.Color.Red

}

}

Thank you for your reading, the above is the content of "the method of writing email with asp.net". After the study of this article, I believe you have a deeper understanding of the method of writing email with asp.net, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report