Sending Mail Using ASP.NET follow process step by step
Step1 : Create user interface to send mail into Default.aspx Page
Step 2: Double click on send button to create button event.
Step 3: Use namespace using system.net.mail;
we will use two classes the MailMessage for the actual email and
SmtpClient for sending email through smtp (simple mail transfter protocol) protocol.
Step 4: Write code into button click event under Default.aspx.cs page
protected void btnsend_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To.Add("xyz@gmail.com") // receiver email
msg.From = new MailAddress("abc@gmail.com") //sender email
msg.Subject =" tech talks email test";
msg.Body = "Hello this is testing email from tech talks";
SmtpClient smtp = new SmtpClient();
smtp.Host ="smtp.gmail.com";
smtp.Port =587 ;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com" , "password");
smtp.EnableSsl = true;
smtp.Send(msg);
}
Please Find another interesting thing related to email :
Attach one or more file :
msg.Attachments.Add(new Attachment(Server.MapPath("~/image.png")));
Set name for the sender :
msg.From = new MailAddress("sender@gmail.com", "sendername");
Send email to more then one person :
msg.To.Add("abc@gmail.com") ;
msg.To.Add("xyz@gmail.com") ;
msg.To.Add("pqr@gmail.com") ;
Send html format email :
msg.IsBodyHtml = true;
Set email priority :
msg.Priority = MailPriority.High;
Set CC and BCC fields :
What is Client Side and Server Side Validation in ASP.NET?
What is Client Side and Server Side Control ?
Step1 : Create user interface to send mail into Default.aspx Page
Step 2: Double click on send button to create button event.
Step 3: Use namespace using system.net.mail;
we will use two classes the MailMessage for the actual email and
SmtpClient for sending email through smtp (simple mail transfter protocol) protocol.
Step 4: Write code into button click event under Default.aspx.cs page
protected void btnsend_Click(object sender, EventArgs e)
{
MailMessage msg = new MailMessage();
msg.To.Add("xyz@gmail.com") // receiver email
msg.From = new MailAddress("abc@gmail.com") //sender email
msg.Subject =" tech talks email test";
msg.Body = "Hello this is testing email from tech talks";
SmtpClient smtp = new SmtpClient();
smtp.Host ="smtp.gmail.com";
smtp.Port =587 ;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com" , "password");
smtp.EnableSsl = true;
smtp.Send(msg);
}
Please Find another interesting thing related to email :
Attach one or more file :
msg.Attachments.Add(new Attachment(Server.MapPath("~/image.png")));
Set name for the sender :
msg.From = new MailAddress("sender@gmail.com", "sendername");
Send email to more then one person :
msg.To.Add("abc@gmail.com") ;
msg.To.Add("xyz@gmail.com") ;
msg.To.Add("pqr@gmail.com") ;
Send html format email :
msg.IsBodyHtml = true;
Set email priority :
msg.Priority = MailPriority.High;
Set CC and BCC fields :
msg.CC.Add("mno@gmail.com");
msg.Bcc.Add("pqr@gmail.com");
What is Client Side and Server Side Validation in ASP.NET?
What is Client Side and Server Side Control ?
No comments:
Post a Comment