Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using System.Net;
using System.Net.Mail;

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

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            string connetionString = "Data Source=INFND-DTP-0493;Initial Catalog=Test_DB;User ID=#####;Password=#####";
            SqlConnection conn = new
            SqlConnection(connetionString);
            conn.Open();
            string commText = "select * from login where user_name='"+txtUserName.Text.Trim()+"' or email_id= '" + txtEmailId.Text.Trim() +"' or phone_no=" + Convert.ToDouble(txtPhoneNo.Text) ;
            SqlCommand cmd = new
            SqlCommand(commText, conn);
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                Label1.Text = "Duplicte of Data";
            }
            else
            {
            conn.Close();
            MailMessage msg;
            string commText1 = "insert into login(User_Name,Password,Address,City,State,PIN,Phone_no,Email_id,Created_By,Created_on) values('" + txtUserName.Text + "','" + txtPassword.Text + "','" + txtAddress.Text + "','" + txtCity.Text + "','" + txtState.Text + "','" + Convert.ToDouble(txtPin.Text) + "','" + Convert.ToDouble(txtPhoneNo.Text) + "','" + txtEmailId.Text +  "','" + "Alok" + "','" + DateTime.Now + "')";
            SqlCommand cmd1 = new 
            SqlCommand(commText1, conn);
            conn.Open();
            int no = cmd1.ExecuteNonQuery();
            conn.Close();
            if(no>0)
             {
            Label1.Text= "User registration sucessfully";
            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
            mail.To.Add(txtEmailId.Text.Trim());
            mail.From = new MailAddress("alokparhi06@gmail.com");
            mail.Subject = "Regarding: Registration conformation";
            mail.Body = "Hi"+txtUserName.Text.Trim()+", You have registered successfully...";
            mail.IsBodyHtml = true;
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("alokparhi06@gmail.com", "xyz");
            client.Port = 587;
            client.Host = "smtp.gmail.com";
            client.EnableSsl = true;
            try
              {
            client.Send(mail);

              }
            catch
              {
            Label1.Text="There is some problem while sending Message... ";	
              }



              }
            else
               {
           Label1.Text="Error";
               }
                
            }
        }
    }
}
Posted
Updated 22-Mar-15 18:33pm
v3
Comments
Modi Mayank 23-Mar-15 0:17am    
Please don't post your personal email/pwd details here. Replace with dummy data before posting it.

What error you are getting?

In meantime, use client.Port = 25; and test your code, else you can get detailed information to send email using gmail in .net here.
[no name] 23-Mar-15 0:19am    
can u show me ur error? put a break point and check which part you got the error?
[no name] 23-Mar-15 0:22am    
what is the error your getting while debug.
.net bigner 23-Mar-15 0:35am    
That not sending error.That is showing catch part.
[no name] 23-Mar-15 0:48am    
comment your label in ur catch section then put below code..
catch(exception ex)
{
throw ex;
//Label1.Text="There is some problem while sending Message... ";
}

Then only we know that the correct expection...

1 solution

Hi,

Previously i was solved this related question..check this ref..
Ref : 5.5.1 Authentication Required
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900