Monday, July 23, 2012

Sending email from your asp.net applications using c#??

now  iam giving some idea to send an email from c#

Put the controls in UI of ur .aspx page.

and write the following code in button click event,

SmtpClient smtpServer = new SmtpClient();
MailMessage mail = new MailMessage();
smtpServer.Credentials = new System.Net.NetworkCredential(TextBox1.Text + "@gmail.com", TextBox2.Text);
smtpServer.Port = 587;
smtpServer.Host = "smtp.gmail.com";
smtpServer.EnableSsl = true;
mail.From = new MailAddress(TextBox1.Text + "@gmail.com");

mail.To.Add(TextBox3.Text);
mail.Subject = TextBox4.Text;
mail.Body = TextBox5.Text;
smtpServer.Send(mail);

string message = "Mail successfully sent..";

ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + message + "');", true);

please dont forget to add the namespaces.

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


Happy coding

have a great day....cherrs

No comments: