Send Email from asp.net using C#


Send Email from asp.net using C#

Requirements:

                   asp.net,c#


send email coding :

             

default.aspx:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="mail.aspx.cs" Inherits="download.mail" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
       <table>
           <tr><td><asp:Label ID="email" runat="server" Text="TO"></asp:Label></td><td><asp:TextBox ID="txtto" runat="server" ></asp:TextBox></td></tr>
           <tr><td><asp:Label ID="text" runat="server" Text="text"></asp:Label></td><td><asp:TextBox ID="txttext" runat="server" ></asp:TextBox></td></tr>
           <tr><td><asp:Label ID="sub" runat="server" Text="Subject"></asp:Label></td><td><asp:TextBox ID="txtsub" runat="server" ></asp:TextBox></td></tr>
           <tr><td></td><td><asp:Button ID="send" runat="server" Text="send" OnClick="send_Click" /></td></tr>
           
       </table>
    </form>
</body>
</html>



default.aspx.cs



using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

namespace download
{
    public partial class mail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            

        }
        public static bool SendMail(string gMailAccount, string password, string to, string subject, string message)
        {

            NetworkCredential loginInfo = new NetworkCredential(gMailAccount, password);
            MailMessage msg = new MailMessage();
            msg.From = new MailAddress(gMailAccount);
            msg.To.Add(new MailAddress(to));
            msg.Subject = subject;
            msg.Body = message;
            msg.IsBodyHtml = true;
            SmtpClient client = new SmtpClient("smtp.gmail.com");
            client.EnableSsl = false;
            client.UseDefaultCredentials = false;
            client.Credentials = loginInfo;
            client.Send(msg);

            return true;


        }

        protected void send_Click(object sender, EventArgs e)
        {
            string username = "sender@gmail.com";
            string password = "test";
            string sub = txtsub.Text;
            string lalmail = txtto.Text;
            

            string msg = txtsub.Text;

            if (SendMail(username, password, lalmail, sub, msg))
            {



            }
        }
    }
}