.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!



Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share

 Subscribe to Code Snippets

Send SMS from asp.net using way2sms account

Posted By:diya       Posted Date: May 16, 2010    Points: 10    Category: ASP.NET Controls    URL:   

hi.. here is the code to send sms from your way2sms account
 

Hello..

here i have given you the link of my code in way2sms

you have to create an account in way2sms before you use this code..

its based on asp.net/c#

you can download the project from:

 login.aspx
 
Mobile No:
Password:

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

To :
Message :
.CS

 string mbno, mseg, ckuser, ckpass;
    private HttpWebRequest req;
    private CookieContainer cookieCntr;
    private string strNewValue;
    public static string responseee;
    private HttpWebResponse response;


protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["id"] == null && Session["pw"] == null)
        {
            Server.Transfer("smslogin.aspx");
        }
        connect();
        
    }

 protected void btnSend_Click(object sender, EventArgs e)
    {       
        try
        {
            mbno = txtTo.Text;
            mseg = txtMessage.Text;
           
            sendSms(mbno, mseg);
            txtTo.Text = "";
            txtMessage.Text = "";
        }
        catch (Exception ex)
        {
            lblError.Text = ex.Message;
            lblError.Visible = true;
        }
    }
    public void connect()
    {
        ckuser = Session["id"].ToString();
        ckpass = Session["pw"].ToString();
      
        try
        {
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com/auth.cl");
           
            this.req.CookieContainer = new CookieContainer();
            this.req.AllowAutoRedirect = false;
            this.req.Method = "POST";
            this.req.ContentType = "application/x-www-form-urlencoded";
            this.strNewValue = "username=" + ckuser + "&password=" + ckpass;
            this.req.ContentLength = this.strNewValue.Length;
            StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
            writer.Write(this.strNewValue);
            writer.Close();
            this.response = (HttpWebResponse)this.req.GetResponse();
            this.cookieCntr = this.req.CookieContainer;
            this.response.Close();
            this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//jsp/InstantSMS.jsp?val=0");
            this.req.CookieContainer = this.cookieCntr;
            this.req.Method = "GET";
            this.response = (HttpWebResponse)this.req.GetResponse();
            responseee = new StreamReader(this.response.GetResponseStream()).ReadToEnd();
            int index = Regex.Match(responseee, "custf").Index;
            responseee = responseee.Substring(index, 0x12);
            responseee = responseee.Replace("\"", "").Replace(">", "").Trim();
            this.response.Close();
          
            pnlsend.Visible = true;
            lblErrormsg.Text = "connected";
        }
        catch (Exception)
        {
            lblErrormsg.Text = "Error connecting to the server...";
            Session["error"] = "Error connecting to the server...";
            Server.Transfer("smslogin.aspx");


        }
    }
    public void sendSms(string mbno, string mseg)
    {
        if ((mbno != "") && (mseg != ""))
        {
            try
            {
                this.req = (HttpWebRequest)WebRequest.Create("http://wwwd.way2sms.com//FirstServletsms?custid=");
                this.req.AllowAutoRedirect = false;
                this.req.CookieContainer = this.cookieCntr;
                this.req.Method = "POST";
                this.req.ContentType = "application/x-www-form-urlencoded";
                this.strNewValue = "custid=undefined&HiddenAction=instantsms&Action=" + responseee + "&login=&pass=&MobNo=" + this.mbno + "&textArea=" + this.mseg;

                string msg = this.mseg;
                string mbeno = this.mbno;

                this.req.ContentLength = this.strNewValue.Length;
                StreamWriter writer = new StreamWriter(this.req.GetRequestStream(), Encoding.ASCII);
                writer.Write(this.strNewValue);
                writer.Close();
                this.response = (HttpWebResponse)this.req.GetResponse();

                this.response.Close();
                lblErrormsg.Text = "Message Sent..... " + mbeno + ": " + msg;
            }
            catch (Exception)
            {
                lblErrormsg.Text="Error Sending msg....check your connection...";
            }
        }
        else
        {
            lblErrormsg.Text = "Mob no or msg missing";
        }
    }

i have created these two pages in my project and you can download the attatchment:


http://www.mediafire.com/?dv0kmznloin

Thank you..





     

Further Readings:

Responses
Author: Nikhil Kumar         Company URL: http://fast-get.com
Posted Date: May 19, 2010

well done diya keep it up... :)
Author: diya         Company URL:
Posted Date: May 20, 2010

thanks nikhil...
Author: Nikhil Kumar         Company URL: http://fast-get.com
Posted Date: May 20, 2010

Diya i have to talk you about a new concept we can work together but first we have talk :
My gtalk id is : nikkibaba007@gmail.com
send me a chat request or accept i have sent you already.
Thanks
nikhil Kumar
Author: Hussain         Company URL: http://www.softronikx.com
Posted Date: October 07, 2010

hi,
I tried the code but it doesnt work. It gives me the output as connected and the number of the person to whom I have sent the message.
But it logs in even when i enter an invalid user Id and password
No message is received on the phone by the user.

I ran the code on localhost with internet connected.

Please let me know whats the issue.

Regards
Hussain Haideri
Author: Shrinivas         Company URL: http://www.dotnetspark.com
Posted Date: February 15, 2011

hi,
I tried the code but it doesn't work. It gives me the output as connected and the number of the person to whom I have sent the message.
But it logs in even when i enter an invalid user Id and password
No message is received on the phone by the user.

I ran the code on local host with internet connected.

Please let me know whats the issue.

Regards
Shrinivas Naik
Author: usharani         Company URL: http://www.dotnetspark.com
Posted Date: February 06, 2012

For the above code we want provide any port number of way2sms api or else what is the code in the web.config file.send me screenshots if possible
Author: varaprasadreddy         Company URL: www.reddyinfosoft.blogspot.in
Posted Date: April 08, 2012

here is the simple solution using way2sms / 160by2 accounts tested and working....

http://www.reddyinfosoft.blogspot.in/2012/04/sending-sms-via-c-using-way2sms-160by2.html
Author: ANIL         Company URL: http://www.dotnetspark.com
Posted Date: September 15, 2012

Its not working,
I am entering Mobile numberAND pass Click connect Noresponse
It will no navigate send.aspx page
plz help me

Post Comment

You must Sign In To post reply

    Read also another Resources from the same Author

Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend