Wednesday, 18 July 2012

How to send mail in asp.Net Using c#

sing System.Net.Mail;

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

    }
    protected void btnSendMail_Click(object sender, EventArgs e)
    {
        try
        {
            string textmag = "";
            textmag = "Sangram Singh<admin@iition.com>";
            MailMessage mgs = new MailMessage(textmag, txtEmail.Text, txtSubject.Text, txtMessage.Text);
            SmtpClient client = default(SmtpClient);
            mgs.IsBodyHtml = true;
            client = new SmtpClient();
            client.Host = "mail.gmail.com";
            client.Credentials = new System.Net.NetworkCredential("admin@gmail.com", "8717574491);
            client.Send(mgs);
            Response.Write("<script>alert('Mail send successfully...')</script>");
        }
        catch
        {
        }
        finally
        {
        }

No comments:

Post a Comment