Get Email on Registration in C#

  • source

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <title></title>    <style type="text/css">        .auto-style1 {            text-align: justify;        }    </style></head><body>    <form id="form1" runat="server">        <div>            <h1> How to send Email</h1>        </div>        <div>            <table>                <tr>                    <td class="auto-style1">                        Enter name                    </td>                    <td>                        <asp:TextBox runat="server" ID="TextBox1"></asp:TextBox>                    </td>                </tr>                <tr>                    <td class="auto-style1">                        Enter email</td>                    <td>                        <asp:TextBox runat="server" ID="TextBox2"></asp:TextBox>                    </td>                </tr>                <tr>                    <td class="auto-style1">                        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="clear" />                    </td>                    <td>                        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="submit" />                    </td>                </tr>                            </table>            <br />            <br />            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>        </div>    </form></body></html>

  • C# Code

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;
using System.Net;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
       
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com";
        smtp.Port = 587;
        smtp.Credentials = new System.Net.NetworkCredential("bhavybarasara@gmail.com", "bhavya2112000@#");
        smtp.EnableSsl = true;
        MailMessage msg = new MailMessage();
        msg.Subject = "Hello " + TextBox1.Text + "  Thanks for Register on alexpatel account";
        msg.Body = "Your Account will hack in 24 hovers";
        string toaddress = TextBox2.Text;
        msg.To.Add(toaddress);
        string fromaddress = " <bhavybarasara@gmail.com>";
        msg.From = new MailAddress(fromaddress);
        try
        {
            smtp.Send(msg);
            Label1.Text = "Your Email Has Been Registered with Us";
            TextBox1.Text = "";
            TextBox2.Text = "";
        }
        catch
        {
            throw;
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        TextBox1.Text = "";
        TextBox2.Text = "";
    }
}
}


NOTE  : Your google account go mygoogle.google.com 
              and ON 

Less secure app access


Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls