locked
Sending a sms message from my website RRS feed

  • Question

  • User813688212 posted

     

     I had  searched in Google for a days and today  I searched through  these forums for hours but no solution convinces me Innocent

    I need a code for a web service that sends sms to a specific mobile when that mobile call it . 

    I  want to run t this code in our windows server computer where our company web sites there .

    I am not familiar in asp.net 

    please can someone gives me a code in c# to do that

    windows server 2003

    visual studio 2008

    windows xp

    Sunday, November 9, 2014 7:42 AM

Answers

  • User281315223 posted

    You'll likely need to use some type of service or SMS Gateway to handle sending SMS messages, which may not always be free (much like sending text messages or phone calls often aren't). The details and implementations may vary for each of them, but you will certainly need an active internet connection (which I am assuming they meant by the modem) to use them (as you would with any sort of web-based technology)

    I'll list a few options for highly recommended SMS Gateways for .NET as well as the code for sending messages for one in particular.

    Overview and Suggestions

    I would recommend checking out the following Stack Overflow discussion on SMS Gateways, which recommended Clickatell. However, there are tons of them out there, so I would suggest doing some research and figuring out what works best for you : 

    Wikipedia also features a fairly comprehensive listing of SMS Gateways as well. 

    Actual Examples

    You will need to use some type of service most likely to perform this, especially if you are going to be performing it on a large scale. SMSified appears to have quite an extensive and friendly API for performing this very task. A fully featured example on sending outbound SMS messages using SMSified can be found here and seen below : 

    // SMSified API endpoint.
    string webTarget = "https://api.smsified.com/v1/smsmessaging/outbound/{0}/requests";
                           
    // Parameters to send with API request.
    string webPost = "address={0}&message={1}";
                           
    // SMSified credentials.
    string userName = "";
    string password = "";
    string senderNumber = "";
                           
    // Create new HTTP request.
    string url = String.Format(webTarget, senderNumber);
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    req.Method = "POST";
    req.ContentType =  "application/x-www-form-urlencoded";
    byte[] postData = Encoding.ASCII.GetBytes(String.Format(webPost, "14075551212", "This is a test from C#"));
    req.ContentLength = postData.Length;
                           
    // Set HTTP authorization header.
    string authInfo = userName + ":" + password;
    authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
    req.Headers["Authorization"] = "Basic " + authInfo;
                           
    // Send HTTP request.
    Stream PostStream = req.GetRequestStream();
    PostStream.Write(postData, 0, postData.Length);
    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

    Likewise, the extremely popular Twilio library can do the same as well :

    // Find your Account Sid and Auth Token at twilio.com/user/account
    string AccountSid = "AC32a3c49700934481addd5ce1659f04d2";
    string AuthToken = "";
    
    // Create a Twilio client using your credentials
    var twilio = new TwilioRestClient(AccountSid, AuthToken);
    var message = twilio.SendMessage("+14158141829", "+14159352345", "This is a test message", "");
    

    You can find some more exhaustive documentation available here.

    Try it out!

    I'm not aware of any free services that would handle sending SMS messages (as I mentioned earlier they are like phone calls or text messages, which typically are not free). I do believe that Twilio offers a "Free Plan" that you may want to look into. I'm sure it has some limitations and restrictions and you would likely need to bump up to the larger packages if you needed such features : 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, November 9, 2014 8:17 AM