sending the mails from c#

Its a simple code for sending the mail from ur c# application
just add the namespacess

using System.Net;
using System.Web.Mail;

then

add the follwing ......

Button1
TextBox1 (set the name in the properties like... txtto)
TextBox2 ( set the name in the properties like.. txtsub)
Textbox3 ( set the name in the properties like .. txtmsgbody
and set the textmode as multiline)
Label1 ( set the name in the properties like .. lblmsg)

write the code

on button_click()
--------------


protected void Button1_Click(object sender, EventArgs e)
{
MailMessage mm = new MailMessage();
try
{
mm.From = "gopiyadavalli@yahoo.com"; // this is ur mail ID
mm.To =txtto .Text.ToString();


mm.Body = txtmsgbody.Text.ToString();
mm.Subject = txtsub.Text.ToString();
System.Web.Mail.SmtpMail.Send(mm);
lblmsg.Text = "Email successfully sent.";

}
catch (Exception ex)
{
lblmsg.Text = "Send Email Failed." + ex.Message;
}

}


Comments

Author: gopi08 Sep 2008 Member Level: Silver   Points : 0

gud its working

thanks for ur coding



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: