Friday, January 7, 2011

ASP.NET Email Send


Contact.aspx
Contact.aspx.cs



using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;

public partial class cont : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ClearControl();

        }

    }
    protected void but_submit_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();

        // mail.To = new MailAddress("anil@abc.in"); mMailMessage.To.Add(new MailAddress(to));
        mail.To.Add(new MailAddress("info@abc.in"));
        mail.From = new MailAddress(txtmail.Text);
        mail.Subject = "Query form APPSYS";
        //mail.Body = txtQuery.Text;
        mail.Body = "<html><body><table><tr><td>Name</td><td>'" + txtname.Text + "'</td></tr><tr><td>Email ID</td><td>'" + txtmail.Text + "'</td></tr> </tr><tr><td>Phone Number </td><td>'" + txtMobile.Text + "'</td></tr> </tr> </tr><tr><td>Query for</td><td>'" + DropDownList1.SelectedItem + "'</td></tr><tr><td>Query</td><td>'" + txtQuery.Text + "'</td></tr></table> </body></html>";
        mail.IsBodyHtml = true;
        mail.Priority = MailPriority.Normal;
        SmtpClient mailclient = new SmtpClient("mail.abc.in");
        mailclient.Credentials = new System.Net.NetworkCredential("anil@abc.in", "XXXX");
        mailclient.Send(mail);

       MessageBox(this, "Thanks For Your Kind Interest We Will Contact you Shortly !");
       // Response.Write("<script>alert('Email-send');</script>");
        ClearControl();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        ClearControl();
    }

    protected void ClearControl()
    {
        txtname.Text = "";
        txtMobile.Text = "";
        txtmail.Text = "";
        txtQuery.Text = "";
        DropDownList1.SelectedIndex = 0;

    }
    public void MessageBox(System.Web.UI.Page page, string Msg)
    {
        string MsgScript = "<script language='javascript'>alert('" + Msg + "')</script>";
        if (!(page.IsStartupScriptRegistered("MessageScript")))
            page.RegisterStartupScript("MessageScript", MsgScript);
    }
}

2 comments :