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


Top 5 Contributors of the Month
satyapriyanayak
Kaviya Balasubramanian
SP
abhays
Sasi Prabhu

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
Author: Yogesh         Company URL:
Posted Date: October 04, 2013

There are many errors in the code? Can anybody help me

Author: Ashok Solanki         Company URL:
Posted Date: March 23, 2014

Mam, I applied this code in my website but i can solve the plsend.Visible=true; error.
so plz tell me what is this error and how to solve this type of error.

If you want to send solution to direct my email than my email address is=solanki.ashok23@gmail.com.
Author: Ravi Shankar Mandal         Company URL:
Posted Date: March 26, 2014

Hi,
Diya..
I have run the program you provided. but it doesn't work for me. it has returned an error. 404 URL not found. Please review this error and back soon with the working code.

thanks....
Author: Ravi Shankar Mandal         Company URL:
Posted Date: March 26, 2014

hey anil you sent these errors with this code-
Its not working,
I am entering Mobile numberAND pass Click connect Noresponse
It will no navigate send.aspx page
plz help me

i found the reason. you are redirecting to send.aspx but due to the error 404 url not found it send.aspx page it is redirecting back to the login page and no change has been seen because the code has used server.redirect method so you can see the url in the address bar is changed but no changes made in the page.

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