Makai Studio
Imi ‘Ike - Seeker Of Knowledge
Imi-?ike

Send Email in ASP.Net C# Sample

November 15, 2007 06:48 by jdelpay

The form is located at www.makaistudio.com/inquiry.aspx For the date picker i used http://www.basicdatepicker.com/bdplite/ its free!

The Code:  

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Net.Mail;
public partial class quoteonline : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

    } 

    protected void btnSendmail_Click(object sender, EventArgs e)

    {

        // we are using System.Net.Mail.SmtpClient in 2.0

        SmtpClient smtpClient = new SmtpClient("smtp.yourdomain.com");
        smtpClient.Credentials = new System.Net.NetworkCredential("contact@yoursite.com", "password");
        MailMessage message = new MailMessage();

      try

        {

            MailAddress fromAddress = new MailAddress(emailtxt.Text, nametxt.Text);  
            // You can specify the host name or ipaddress of your server
 
            // Default in IIS will be localhost
            //smtpClient.Host = "smtp.yourSMTPinfo.com";
            //If SMTP server requires a secure connection or the authenticated 
            //Default port will be 25

            smtpClient.Port = 25; 
            //From address will be given as a MailAddress Object 
            message.From = fromAddress; 
            // To address collection of MailAddress 
            message.To.Add(contact@yoursite.com);
            message.Subject = "Quote"

            // CC and BCC optional 
            // MailAddressCollection class is used to send the email to various users
            // You can specify Address as new MailAddress(admin1@yoursite.com)
            //message.CC.Add("info@yoursite.com");
            //message.CC.Add("sales@yoursite.com");  
            // You can specify Address directly as string 
            //message.Bcc.Add(new MailAddress(admin2@yoursite.com)); 
            //message.Bcc.Add(new MailAddress("admin3@yoursite.com")); 

            //Body can be Html or text format

            //Specify true if it  is html message

            message.IsBodyHtml = false

            // Message body content

            message.Body = "Name: "+nametxt.Text+"\n"+"Email: "+emailtxt.Text+"\n"+"Business: "+businesstxt.Text+"\n"+"Phone: "+phonetxt.Text+"\n"+"Current Website: "+currentwebsitetxt.Text+"\n"+"Service Needed: "+CheckBoxList1.SelectedValue+"\n"+"Project Deadline: "+BDPLite1.SelectedDate+"\n"+"Adds on or Modules: "+CheckBoxList2.SelectedValue+" "+CheckBoxList3.SelectedValue+" "+CheckBoxList4.SelectedValue+"\n"+"Preferred Site: "+siteyoulike1txt.Text+" "+siteyoulike2txt.Text;

              // Send SMTP mail

            smtpClient.Send(message); 
            lblStatus.Text = "Email successfully sent."
            Response.Redirect("thankyou.aspx?Name=" + nametxt.Text);// Read my tutorial on how to xfer pages values to another                       

 

        }

        catch (Exception ex)

        {

            lblStatus.Text = "Send Email Failed." + ex.Message;

        }

    }

    protected void BDPLite1_SelectionChanged(object sender, EventArgs e)

    {

        BDPLite1.DateFormat = "d";

        Response.Write(BDPLite1.SelectedDateFormatted);

    }


Visit:Makai Studio

AddThis Social Bookmark Button

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: ASP.Net
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

May 16. 2008 14:38