how to send mail by c#?
how to send mail by c#?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SchelianHPPosted Nov 12, 2004, 6:16 AM
shehan_1983Posted Nov 12, 2004, 2:20 AM
fadil1977Posted Nov 8, 2004, 2:06 AM
using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Web.Mail ; namespace C_sharp { ///
/// Summary description for Email.
///
public class Email : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.DropDownList listSubject;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button Button1;
private void Page_Load(object sender, System.EventArgs e)
{
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
if ((this.TextBox1.Text=="")|| (this.listSubject.SelectedItem.Text=="Nothing"))
{
this.Label1.Visible= false;
this.Label2.Visible=true;
//return;
}
else
if ((this.TextBox1.Text.Trim()=="" )|| (this.listSubject.SelectedItem.Text=="Nothing"))
{
this.Label1.Visible= false;
this.Label2.Visible=true;
//return;
}
else
{
// Put user code to initialize the page here
MailMessage msgMail = new MailMessage();
msgMail.To = "[email protected],[email protected]";//can have more than one person
//msgMail.Cc = "[email protected]";
msgMail.From = "[email protected]";
//msgMail.Subject = "Hi fadil!, done!!";
msgMail.Subject = this.listSubject.SelectedItem.Text;// instead of text
msgMail.BodyFormat = MailFormat.Html;
//string strBody = "Hello World" +
// " ASP.NET";
string strBody = this.TextBox1.Text;
msgMail.Body = strBody;
msgMail.Attachments.Add(new MailAttachment("C:\\aaa.doc"));
SmtpMail.Send(msgMail);
this.Label1.Visible=true;
this.Label2.Visible = false;
this.TextBox1.Text=null;
}
}
}
}
bilnaadPosted Nov 7, 2004, 1:04 PM