Code for Sending E-Mail with System.Web.Mail?

Answer Posted / ramesh

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net;
using System.Net.Mail;

public partial class email : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
NetworkCredential mylogin = new
NetworkCredential("yraddress@gmail.com","yourpassword");
MailMessage msg = new MailMessage();
msg.From = new MailAddress("yraddress@gmail.com@gmail.com");
msg.To.Add(new MailAddress(TextBox1.Text));
// in Textbox1 you will put receiver gmail address,as this
example work with gmail only.
msg.Subject = TextBox2.Text;
// subject pass through textbox2
msg.SubjectEncoding = System.Text.Encoding.UTF8;
msg.Body = TextBox3.Text;
//msgbody pass through textbox3
msg.Priority = MailPriority.High;
msg.IsBodyHtml = true;

SmtpClient client = new
SmtpClient("smtp.gmail.com");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = mylogin;
client.Send(msg);


}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Coding for .NET Delegates?

2086


Common UI for Multiple web applications. Suppose there are 35 websites using same third party controls.These 3rd party controls are made together that all 35 websites can use these controls.If we put all 3rd party controls and use its dll in 35 websites,only class files will be accessable. But I want to use CSS,images also in all 35 websites. how I can design the N-tier solution for this project.

2246


Code for Creating a Form Using PlaceHolder Controls?

2339


how to create a search bar which access data from various websites and retrieves the data

2546


i have a gird with columns all are coming from database,this will bind in item templete in gridview as textboxex.and i have button below named Update.i want to update all the records in the grid,but if user change the value of one textbox,what is the easy way 2 do this

2137






Code for Communicating over Sockets?

1938


Coding for Synchronizing Cache Access in ASP.NET?

3113


How to get Dynamically Linked Comboboxes Set?

2019


Code for Presenting Parent/Child Data in a Data Grid Row?

2102


What is the code of Password Recovery or Forget your password? Plz tell in c # language.

3561


Code for Document Validation in XML.NET?

1977


how to track links visited in google using iframes

2272


ArrayList declaration in .net

2741


Code for Using Keyboard Events?

2124


How we use ajax in asp.net through javaScript. Please givee me an example.

2497