Mail send test. Codebehind

Source: Internet
Author: User
Tags mail
Using System;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using Blood.Com.ClassLib;

Namespace Test
{
<summary>
Mail Send Example
</summary>
public class SendMailSample:System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.DropDownList ddlpriority;
protected System.Web.UI.WebControls.DropDownList ddlhtml;
protected System.Web.UI.WebControls.TextBox txtsmtphost;
protected System.Web.UI.WebControls.TextBox Txtport;
protected System.Web.UI.WebControls.TextBox Txtfrom;
protected System.Web.UI.WebControls.TextBox txtfromname;
protected System.Web.UI.WebControls.TextBox Txtto;
protected System.Web.UI.WebControls.TextBox txttoname;
protected System.Web.UI.WebControls.TextBox Txtsubject;
protected System.Web.UI.WebControls.TextBox txtmessage;
protected System.Web.UI.WebControls.RegularExpressionValidator Revport;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvsmtphost;
protected System.Web.UI.WebControls.RequiredFieldValidator Rfvport;
protected System.Web.UI.WebControls.RequiredFieldValidator Rfvfrom;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvto;
protected System.Web.UI.WebControls.RequiredFieldValidator Rfvsubject;
protected System.Web.UI.WebControls.RequiredFieldValidator rfvmessage;
protected System.Web.UI.WebControls.Button Btnsendmail;
protected System.Web.UI.WebControls.Label lblmessage;
protected System.Web.UI.WebControls.RegularExpressionValidator Revfrom;
protected System.Web.UI.WebControls.RegularExpressionValidator revto;
protected System.Web.UI.WebControls.Panel pelmessage;

private void Page_Load (object sender, System.EventArgs e)
{
}

#region Web Form Designer generated code
Override protected void OnInit (EventArgs e)
{
//
Codegen:this the call are required by the ASP.net Web Form Designer.
//
InitializeComponent ();
Base. OnInit (e);
}

<summary>
Required to Designer support-do not modify
The contents is with the Code Editor.
</summary>
private void InitializeComponent ()
{
This.btnSendMail.Click + = new System.EventHandler (This.btnsendmail_click);
This. Load + = new System.EventHandler (this. Page_Load);

}
#endregion

private void Btnsendmail_click (object sender, System.EventArgs e)
{
if (IsPostBack)
{
SmtpMail clsmail = new SmtpMail ();
string strsmtphost = Txtsmtphost.text;
int intport = Int32.Parse (Txtport.text);
string strfrom = Txtfrom.text;
string strfromname = Txtfromname.text;
string strto = Txtto.text;
string strtoname = Txttoname.text;
Smtpmail.prioritys Priority = SMTPMail.Prioritys.NORMAL;
BOOL bolhtml;
string strsubject = Txtsubject.text;
string strmessage = Txtmessage.text;
if (DdlPriority.SelectedItem.Text = = "Default")
{
Priority = SMTPMail.Prioritys.NORMAL;
}
else if (DdlPriority.SelectedItem.Text = "High")
{
Priority = SMTPMail.Prioritys.HIGH;
}
else if (DdlPriority.SelectedItem.Text = "Low")
{
Priority = SMTPMail.Prioritys.LOW;
}
if (DdlHtml.SelectedItem.Text = = "Yes")
{
Bolhtml = true;
}
Else
{
Bolhtml = false;
}
Clsmail.sendmail (strsmtphost,intport,strfrom,strfromname,strto,strtoname,priority,bolhtml, "", StrSubject, strmessage);
if (clsmail.errormessage!= "")
{
Pelmessage.visible = true;
Lblmessage.text = Clsmail.errormessage;
Lblmessage.forecolor = System.Drawing.Color.Red;
}
Else
{
Pelmessage.visible = true;
Lblmessage.text = "Mail sent successfully";
Lblmessage.forecolor = System.Drawing.Color.Blue;
}
}
}
}
}


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.