Wednesday, 12 December 2012

Send SMS from asp.net using way2sms account

Send SMS from asp.net using way2sms account

login.aspx

01<table runat="server" id="tblconnect" width="500">
02
03
04    <tbody><tr>
05                    <td>
06                        Mobile No:
07                    </td>
08                    <td>
09                        <asp:textbox id="txtmobileno" runat="server"></asp:textbox>
10                    </td>
11                </tr>
12                <tr>
13                    <td>
14                        Password:
15                    </td>
16                    <td>
17                        <asp:textbox id="txtpw" runat="server" textmode="Password"></asp:textbox>
18                    </td>
19                </tr>
20                <tr>
21                    <td colspan="2" align="Center">
22                    <br>
23                        <asp:linkbutton id="btnconnect" width="60" borderwidth="1" borderstyle="Groove" runat="server" text="Connect" onclick="btnconnect_Click">
24                    </asp:linkbutton></td>
25                </tr>
26</tbody></table>
.cs

1protected void btnconnect_Click(object sender, EventArgs e)
2{
3    Session["id"] = txtmobileno.Text;
4    Session["pw"] = txtpw.Text;
5    Response.Redirect("Sendsms.aspx");
6}
Sendsms.aspx


01<table runat="server" id="sendsms">
02                <tbody><tr>
03                    <td>
04                        To :
05                    </td>
06                    <td>
07                        <asp:textbox id="txtTo" runat="server" height="30px" autocompletetype="BusinessPhone" width="180px"></asp:textbox>
08                    </td>
09                </tr>
10                <tr>
11                    <td>
12                        Message :
13                    </td>
14                    <td>
15                        <asp:textbox id="txtMessage" runat="server" textmode="MultiLine" height="150px" maxlength="140"></asp:textbox>
16                    </td>
17                </tr>
18                <tr>
19                    <td colspan="2">
20                        <span style="float: right;">
21                            <asp:label id="lblLeft" enabled="false" runat="server" text="Characters left 140"></asp:label></span>
22                    </td>
23                </tr>
24                <tr>
25                    <td colspan="2">
26                        <asp:label id="lblError" runat="server" width="100%"></asp:label>
27                    </td>
28                </tr>
29                <tr>
30                    <td colspan="2">
31                        <center>
32                            <asp:button cssclass="button" id="btnSend" runat="server" text="Send" onclick="btnSend_Click">
33                        </asp:button></center>
34                    </td>
35                </tr>
36            </tbody></table>
.CS


001string mbno, mseg, ckuser, ckpass;
002    private HttpWebRequest req;
003    private CookieContainer cookieCntr;
004    private string strNewValue;
005    public static string responseee;
006    private HttpWebResponse response;
007
008
009protected void Page_Load(object sender, EventArgs e)
010    {
011        if (Session["id"] == null && Session["pw"] == null)
012        {
013            Server.Transfer("smslogin.aspx");
014        }
015        connect();
016         
017    }
018
019 protected void btnSend_Click(object sender, EventArgs e)
020    {      
021        try
022        {
023            mbno = txtTo.Text;
024            mseg = txtMessage.Text;
025            
026            sendSms(mbno, mseg);
027            txtTo.Text = "";
028            txtMessage.Text = "";
029        }
030        catch (Exception ex)
031        {
032            lblError.Text = ex.Message;
033            lblError.Visible = true;
034        }
035    }
036    public void connect()
037    {
038        ckuser = Session["id"].ToString();
039        ckpass = Session["pw"].ToString();
040       
041        try
042        {
043            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");
044            
045            this.req.CookieContainer = new CookieContainer();
046            this.req.AllowAutoRedirect = false;
047            this.req.Method = "POST";
048            this.req.ContentType = "application/x-www-form-urlencoded";
049            this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
050            this.req.ContentLength = this.strNewValue.Length;
051            StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
052            writer.Write(this.strNewValue);
053            writer.Close();
054            this.response = (HttpWebResponse)this.req.GetResponse();
055            this.cookieCntr = this.req.CookieContainer;
056            this.response.Close();
057            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
058            this.req.CookieContainer = this.cookieCntr;
059            this.req.Method = "GET";
060            this.response = (HttpWebResponse)this.req.GetResponse();
061            responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
062            int index = Regex.Match(responseee, "custf").Index;
063            responseee = responseee.Substring(index, 0x12);
064            responseee = responseee.Replace("\"", "").Replace(">", "").Trim();
065            this.response.Close();
066           
067            pnlsend.Visible = true;
068            lblErrormsg.Text = "connected";
069        }
070        catch (Exception)
071        {
072            lblErrormsg.Text = "Error connecting to the server...";
073            Session["error"] = "Error connecting to the server...";
074            Server.Transfer("smslogin.aspx");
075
076
077        }
078    }
079    public void sendSms(string mbno, string mseg)
080    {
081        if ((mbno != "") && (mseg != ""))
082        {
083            try
084            {
085                this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//FirstServletsms?custid=");
086                this.req.AllowAutoRedirect = false;
087                this.req.CookieContainer = this.cookieCntr;
088                this.req.Method = "POST";
089                this.req.ContentType = "application/x-www-form-urlencoded";
090                this.strNewValue = "custid=undefined&HiddenAction=instantsms&Action=" + responseee + "&login=&pass=&MobNo=" + this.mbno + "&textArea=" + this.mseg;
091
092                string msg = this.mseg;
093                string mbeno = this.mbno;
094
095                this.req.ContentLength = this.strNewValue.Length;
096                StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
097                writer.Write(this.strNewValue);
098                writer.Close();
099                this.response = (HttpWebResponse)this.req.GetResponse();
100
101                this.response.Close();
102                lblErrormsg.Text = "Message Sent..... " + mbeno + ": " + msg;
103            }
104            catch (Exception)
105            {
106                lblErrormsg.Text="Error Sending msg....check your connection...";
107            }
108        }
109        else
110        {
111            lblErrormsg.Text = "Mob no or msg missing";
112        }
113    }
                                                
Download:
http://www.mediafire.com/?dv0kmznloin

 

2 comments:

  1. Sometimes my account does not open. Getting error way2sms login failed. Actually, i do not know how it happens only with me. In such a situation, i'll open another site such as 160by2, ultoo and smsspark.

    ReplyDelete