asp.net email examples _ Practical tips

Source: Internet
Author: User

Copy Code code as follows:

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 = * * * Read template error (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 + "] Create a loan slip";
//--------------------------------------------------------------------------
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 + "] Create a loan slip";

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)//approver
BODY = Body.replace ("Dttpl_comm_module_name_time", Tbxdebttime_add.text)/borrowing time
BODY = Body.replace ("Dttpl_comm_module_name_advance", tbadvance.text)//payday unit
BODY = Body.replace ("Dttpl_comm_module_name_debtpathway", DdlDebtPathWay.SelectedItem.Text)/borrowing method
BODY = Body.replace ("Dttpl_comm_module_name_remark", Txbmemo_add.text);
BODY = Body.replace ("Dttpl_comm_module_name_mend", "")//Audit opinion
BODY = Body.replace ("Dttpl_comm_module_name_memo", "");/note
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 = "* * * Save success of the loan sheet! But the responsible person/concern person because in the database does not have the mailbox address, the Mail has not 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 = "* * * Send failed (the email is not sent)!" + ex. ToString ();
Lbmessage.forecolor = System.Drawing.Color.Red;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.