Monday, 5 January 2015

How to send free SMS from ASP.Net application to Mobile

In this article I am explain how to send Free SMS and Free Bulk SMS to mobile (cell) numbers in ASP.Net website. There are many websites that allow sending free SMS to mobile (cell) numbers like Way2sms, FullOnSMS, 160by2, Site2SMS, IndyaRocks.com SMSAbc.com, Ultoo.com, SmsSpark.com SMSFI.com Freesms8, Sms440, BhokaliSMS, etc.

The above sites allow users to send Free SMS to any Mobile or Cell Number.
Thus to make it easier for the .Net Community I have introduced an API for sending SMS using Site2SMS which uses the online API from Mashape.com.
In order to use this API you need to

1. Register at Site2SMS and get Username and Password.

2. Register at Mashape.com and generate key.
3. Download DLL Here.

Designer Source Code:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        body
        {
            font-family: Arial;
            font-size: 10pt;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <table border="0">
        <tr>
            <td>
                Your Number:
            </td>
            <td>
                <asp:TextBox ID="txtNumber" runat="server"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Required"
                    ControlToValidate="txtNumber" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                Password:
            </td>
            <td>
                <asp:TextBox ID="txtPassword" TextMode="Password" runat="server"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="Required"
                    ControlToValidate="txtPassword" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                Recipient Number:
            </td>
            <td>
                <asp:TextBox ID="txtRecipientNumber" runat="server" Width="300"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Required"
                    ControlToValidate="txtRecipientNumber" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
                Message:
            </td>
            <td>
                <asp:TextBox ID="txtMessage" runat="server" TextMode="MultiLine"></asp:TextBox>
            </td>
            <td>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ErrorMessage="Required"
                    ControlToValidate="txtMessage" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td>
            </td>
            <td>
                <asp:Button ID="btnSend" runat="server" Text="Send" OnClick="btnSend_Click" />
            </td>
            <td>
            </td>
        </tr>
    </table>
    </form>
</body>
</html>

Code Behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Net;
using System.IO;
using ASPSnippets.SmsAPI;

public partial class CS : System.Web.UI.Page
{
    protected void btnSend_Click(object sender, EventArgs e)
    {
        SMS.APIType = SMSGateway.Site2SMS;
        SMS.MashapeKey = "<Mashape API Key>";https://www.mashape.com
        SMS.Username = txtNumber.Text.Trim();
        SMS.Password = txtPassword.Text.Trim();
        if (txtRecipientNumber.Text.Trim().IndexOf(",") == -1)
        {
            //Single SMS
            SMS.SendSms(txtRecipientNumber.Text.Trim(), txtMessage.Text.Trim());
        }
        else
        {
            //Multiple SMS
            List<string> numbers = txtRecipientNumber.Text.Trim().Split(',').ToList();
            SMS.SendSms(numbers, txtMessage.Text.Trim());
        }
    }
}


Please Like and Share this article ...

No comments:

Post a Comment