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. etettings ["AddresserMail_1"]. ToString ();
Me_1.AddresserName = ConfigurationManager. AppSettings ["AddresserName_1"]. ToString ();
Me_1.AddresserPwd = ConfigurationManager. etettings ["AddresserPwd_1"]. ToString ();
String strPostfix = ConfigurationManager. receivettings ["Postfix"]. ToString ();
String isSend = ConfigurationManager. receivettings ["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 = "*** An error occurred while reading the template (reading template failed )! "+ Ex. Message;
LbMessage. ForeColor = System. Drawing. Color. Red;
Return;
}
//--------------------------------------------------------------------------
Me. ClientHost = ConfigurationManager. receivettings ["clientHost"]. ToString ();
Me. MailEncoding = System. Text. Encoding. GetEncoding ("GB2312 ");
Me. MailPriority = System. Net. Mail. MailPriority. Normal;
Me. IsBodyHtml = true;
Me. Subject = "[" + CreaterName + "] created borrow ticket ";
//--------------------------------------------------------------------------
Me_1.ClientHost = ConfigurationManager. receivettings ["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 borrow ticket ";
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); // reviewer
Body = Body. Replace ("DTTPL_COMM_MODULE_NAME_Time", tbxDebtTime_Add.Text); // loan time
Body = Body. Replace ("DTTPL_COMM_MODULE_NAME_Advance", tbAdvance. Text); // The Payment Unit
Body = Body. Replace ("DTTPL_COMM_MODULE_NAME_DebtPathWay", ddlDebtPathWay. SelectedItem. Text); // method of borrowing
Body = Body. Replace ("DTTPL_COMM_MODULE_NAME_Remark", txbMemo_Add.Text); // borrow reason
// Body = Body. Replace ("DTTPL_COMM_MODULE_NAME_Mend", ""); // review comments
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 borrow order is saved successfully! However, the owner/followers do not have an email address in the database and the email has not been sent! ";
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 = "*** sending failed (the email is not sent )! "+ Ex. ToString ();
LbMessage. ForeColor = System. Drawing. Color. Red;
}
}