.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Email >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Sending Auto generated Emails.

Posted By:Ashutosh Jha       Posted Date: May 01, 2014    Points: 40    Category: Email    URL: http://www.dotnetspark.com  

Here i will explain how to send auto emails in asp.net.
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class PostQuery : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void submit_Click(object sender, EventArgs e)
    {
        try
        {
            MailMessage Msg = new MailMessage();
            
            Msg.From = new MailAddress("XXXX@gmail.com");
            // Recipient e-mail address.
            Msg.To.Add("ashutosh@gmail.com");
            Msg.Subject = "Alert For Contacted User!";
            
            Msg.Body = "One user  " + name.Text + " with EmailID "+emailid.Text+" and Contact # "+number.Text+"  has contacted you rerading query "+description.Text+ ". plesae get in touch";
           
            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            
            smtp.Port = 587;
            //Sender mail id and password
            smtp.Credentials = new System.Net.NetworkCredential("XXXXX@gmail.com", "XXXX");
            smtp.EnableSsl = true;
            smtp.Send(Msg);
            Msg = null;
            ClientScript.RegisterClientScriptBlock(this.GetType(), "myscript", "alert('Thank you for contacting us.We will get back to you soon!');", true);
            //this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
           
        }
        catch (Exception ex)
        {
            Console.WriteLine("{0} Exception caught.", ex);
        }
        name.Text = "";
        emailid.Text = "";
        number.Text = "";
        description.Text = "";
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
    }
    protected void reset_Click(object sender, EventArgs e)
    {
        name.Text = "";
        emailid.Text = "";
        number.Text = "";
        description.Text = "";
        
    }
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend