How to send an email or perform other operation from .aspx page without CS or Vb file ASP.net

Using below method you can send the email fromaspx page directly, no need of aspx.cs/vb file.
There is one text boxes and a submit button on .aspx page and on button click , get the data from textbox and send in email

<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import Namespace="System.IO" %>

  
  <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="sendData" />
        <script runat="server">
            protected void Button1_Click(object sender, EventArgs e)
            {
                //create the mail message
                MailMessage mail = new MailMessage();

                //set the addresses
                mail.From = new MailAddress("info@infoA2Z.com");
                mail.To.Add("Support@infoA2Z.com");

                //set the content
                mail.Subject = "This is an email";
                mail.Body = "this is the body content of the email.";

                //send the message
                SmtpClient smtp = new SmtpClient();
                smtp.Send(mail);
            }
        </script>
 <asp:TextBox ID="txtBodyContent"   runat="server"></asp:TextBox>

Related Alrticles

Add Your Business in Free Listing


FREE!!! Registration