Professionallearn.com

[ Log On ]
< <
 

Articles

Posted By: P.R.S
7/31/2012 12:00:00 AM
language: C#

 

Sending email from a web page is one of the most common functionality required from a web site. 

The System.Web.Mail Namespace in the .NET Framework contains the required support classes and enumerations for email capabilities.

The main classes used are System.Web.Mail.MailMessage and the SmtpMail class.  contains the listing for a simple web form to send email. This form assumes that the SMTP service is running on the serve

 

Step 1  Add Code in .cs File

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Web.Mail;
using System.Net.Mail;
using System.Net.NetworkInformation;
using System.Net;
using System.Net.Mime;
public partial class enquiry : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void submit_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
           
            

            const string Email_to = "info@thevags.com";
            //const string Email_from = txt_emailid.Text;
            string Email_from = email.Text;
            System.Net.Mail.MailMessage mailmsg = new System.Net.Mail.MailMessage(Email_from, Email_to);

            mailmsg.Subject = "Enquire with us";
            mailmsg.Body = "Name:-" + firstname.Text + "<br>Company Name:-" + cname.Text + "<br>Address:-" + Address.Text + "<br>Designation:-" + designation.Text + "<br> Contact No:-" + phone.Text + "<br>Email :-" + email.Text + "<br>Enquiry :-" + enquiries.Text + "";
            
            mailmsg.IsBodyHtml = true;


            SmtpClient smtpsend = new SmtpClient();
            smtpsend.Send(mailmsg);

            
            msg.Text = "Request Successfully Send";
            
        }
        catch (Exception ex)
        {
            //Label22.Visible = true;
            // msg.Text = "Message Not send please fill all field";
            //Label21.Visible = false;
        }
    }
    
}

 

 

Step 2 Add code in web.config file just below in  </runtime>

 

<system.net>
    <mailSettings>
      <smtp from="info@xyz.com">
        <network host="mail.xyz.com" userName="info@xyz.com" password="xyz" />
      </smtp>
    </mailSettings>
  </system.net>

 

Share Your Source Code or Article

Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.

Submit now...

Sponsor