Top Ad unit 728 × 90

How to Send bulk sms using asp.net c#

Today I am discussing about How to Send Bulk Sms in Asp.net C#.It is simple to send sms and email by asp.net web application with C#.


Step 1:Create a sql database table according to your requirement.
Step 2:Create an empty asp.net website.
Step 3:Get sms api and password  from any api provider for bulk sms.
Step 4:Get SMTP Id and password for sending bulk email.

Send Bulk Sms Using asp.net c#


Step 1:
Create a sql table to store name,mobile number and email id.You can add more fields according to your requirements.

Create table ClientData
(
Client_Id int identity(1,1),
Client_Name varchar(100),
Mobile_No bigint,
Email_Id varchar(250)

)

Step 2:
Create an empty asp.net website.For data entry you can design a simple interface with your required data table fields.I am using Name,Mobile No and Email ID,you can add fields according to your requirements.Bellow code to insert data from your web form to database on asp.net button click:


 protected void submitButton_Click(object sender, EventArgs e)
    {

string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                   using (System.Data.SqlClient.SqlConnection sqlCon1 = new System.Data.SqlClient.SqlConnection(constr))
                   {
                       using (System.Data.SqlClient.SqlCommand cmd1 = new System.Data.SqlClient.SqlCommand())
                       {

                           cmd1.CommandText = "insert into ClientData(Client_Name,Mobile_No,Email_Id) values('" +

textboxName.Text + "','" + textboxMobile.Text + "','" + textboxEmail.Text+ "') SELECT @@IDENTITY";
                           cmd1.Connection = sqlCon1;
                           sqlCon1.Open();
                           int id = Convert.ToInt32(cmd1.ExecuteScalar());
                           string Client_Id = String.Format("Client ID is {0}", id);
                       
                           Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Alert", "alert('Client Added with Id:"+idd+"

')", true);
                         
                       }
                   }
}





Step 3:

Get sms api with user id and password.There are many free sms gateway providers whom you can ask for api user name and password or you can also get a gateway api id and password from paid bulk sms providers.

Step 4:

To send email from your web application you need SMTP port with id and password.You can use your Gmail id or password for this task.

Complete code bellow for How to send Sms and Email from Asp.net C#:

Code to show client records on asp.net gridview:

private void GetClientRecords()
    {
        string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        using (System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection(constr))
        {
            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
            {
             
                cmd.CommandText = "select * from ClientData";
                cmd.Connection = sqlConn;
                sqlConn.Open();
                System.Data.SqlClient.SqlDataAdapter da1 = new System.Data.SqlClient.SqlDataAdapter(cmd);
                System.Data.DataTable dt1 = new System.Data.DataTable();


                da1.Fill(dt1);

                GridView1.DataSource = dt1;
                GridView1.DataBind();


                sqlConn.Close();
            }
        }
    }


Code to BindData to asp.net gridview GridView1:


    
        
        
                
                
            
         
                
            
        
        
        
        
    


Bellow code to check all records at a time:

Javascript code:

Cs code:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Header)
        {
            ((CheckBox)e.Row.FindControl("allchk")).Attributes.Add("onclick","javascript:SelectAll('" +((CheckBox)

e.Row.FindControl("allchk")).ClientID + "')");
        }

    }

Bellow code to send Sms on Send_Sms button Click:

protected void SendSms()
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                if ((row.FindControl("CheckBox1") as CheckBox).Checked)
                {
                    try
                    {
                       string uid = "Your_Api_Id";
                       string password = "Your_Sms_Api_Password";
                       string message = "Your Sms";
                     
                     
                        string no= row.Cells[2].Text;
                        string content = txtcontent.Text;
                        System.Net.HttpWebRequest myReq = (System.Net.HttpWebRequest)System.Net.WebRequest.Create

("http://yourapiurl.com/api/sendsms.aspx?user=abcdemail@gmail.com&apikey=APIKEY&mobile=91" + no +

"&message=" + message + "&senderid=xxyy&type=txt");



                        System.Net.HttpWebResponse myResp = (System.Net.HttpWebResponse)myReq.GetResponse();
                        System.IO.StreamReader respStreamReader = new System.IO.StreamReader

(myResp.GetResponseStream());
                        string responseString = respStreamReader.ReadToEnd();
                        respStreamReader.Close();
                        myResp.Close();
                    }
                    catch
                    { }
                }
            }
        }
    }



If you have any question regarding How to Send Sms in Asp.net C# you can ask question or you can ask for complete project with source code.


How to Send bulk sms using asp.net c# Reviewed by Abdul Moid on November 28, 2015 Rating: 5

Contact Form

Name

Email *

Message *

Powered by Blogger.