Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

.NET SMS sending DLL

  • 16-05-2008 9:56am
    #1
    Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭


    I whipped together a class to send SMSs using C# (or any .NET managed language). Here it is should anyone find it useful.

    http://conormccarthy.com/box/netsms.dll


    Example use (in C#):
    using NetSms;
    .
    .
    .
    SMSSender s = new SMSSender();
    s.Login = "0861234567";
    s.Password = "passwordOrPin";
    s.Provider = SMSSender.ProviderEnum.O2;
    int remaining = s.Send("0861234567", "Will it work?");
    Console.WriteLine(remaining);
    Console.ReadKey();
    

    So just add the DLL to your project, include the NetSms namespace, create a SMSSender object and set your login information including the provider using one of the following Enums.

    ProviderEnum.METEOR
    ProviderEnum.O2
    ProviderEnum.VODAFONE


    Then call the .Send method of the object with the recipient number and message.

    This works by passing the request through the http://cabaal.org/cabbage/ web sms system. So if that goes down, the SMSs won't get sent. On the other hand, if O2 etc change their system and break the interface, the SMSs will continue to work as long as the cabbage site is updated.

    If you don't want your SMSs going through the cabbage site you can set the
    Url property of the SMSSender object to a different location - somewhere containing the PHP files that can be downloaded from the cabbage web site.

    ps. I'm not affiliated with the cabbage people.


Comments

  • Registered Users, Registered Users 2 Posts: 9,579 ✭✭✭Webmonkey


    Good stuff, always nice to see this stuff.


  • Registered Users, Registered Users 2 Posts: 2,835 ✭✭✭StickyMcGinty


    this is excellent, great work out of ye!

    did my final year project in C#, if the demo wasnt next week i would have given this a bash!


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Good work, I'm gonna a find a use this for this in my future projects, thanks very much :)


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    great work, whatever happened to those stand alone txt senders?
    i was trying to develop one in flex for meteor but couldnt find where the request was going to :(


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Good stuff. I'm glad it actually works :)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Placebo wrote: »
    great work, whatever happened to those stand alone txt senders?
    i was trying to develop one in flex for meteor but couldnt find where the request was going to :(

    jsms is one that works well.
    http://jsmsirl.sourceforge.net/JSMS/JSMS.html


  • Closed Accounts Posts: 94 ✭✭Done and dusted


    Excellently well done!

    I wrote something similar awhile back but this is much better. Congrats again!

    Dont forget ppl if your using this in your projects give credit to the OP :D

    Can we look at the DLL src?


  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    Just use .Net Reflector to look at the source!


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Here you go.
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Web;
    using System.IO;
    
    namespace NetSms
    {
        public class SMSSender
        {
            private string url;
            private string login;
            private string password;
            private ProviderEnum provider;
            /// <summary>
            /// Gets and sets the url of the cabaal php file locations
            /// Include training slash
            /// </summary>
            public string Url
            {
                get
                {
                    return url;
                }
                set
                {
                    url = value;
                }
            }
            /// <summary>
            /// Gets and sets the login string (eg. your telephone number)
            /// </summary>
            public string Login
            {
                get
                {
                    return login;
                }
                set
                {
                    login = value;
                }
            }
            /// <summary>
            /// Gets and sets the password string
            /// </summary>
            public string Password
            {
                get
                {
                    return password;
                }
                set
                {
                    password = value;
                }
            }
            /// <summary>
            /// Gets and sets the provider string (m (meteor), v (vodafone)m, o (o2)) 
            /// </summary>
            public ProviderEnum Provider
            {
                get
                {
                    return provider;
                }
                set
                {
                    provider = value;
                }
            }
    
            /// <summary>
            /// Creates SMSSender
            /// </summary>
            public SMSSender()
            {           
                Url = "http://cabaal.org/cabbage/";
                Provider = ProviderEnum.METEOR;
            }
    
            /// <summary>
            /// Sends an SMS
            /// Ensure you have set Login, Password, Provider and optionally Url before calling this.
            /// </summary>
            /// <param name="to">telephone number to send to</param>
            /// <param name="content">SMS content</param>
            /// <param name="maxNumberOfMessages">Maximum no no messages to use before truncation of content</param>
            /// <returns>Number of messages remaining</returns>
            public int Send(string to, string content)
            {
                return Send(to, content, 1);
            }
            /// <summary>
            /// Sends an SMS
            /// Ensure you have set Login, Password, Provider and optionally Url before calling this.
            /// </summary>
            /// <param name="to">Telephone number to send to. Eg. 0851234567</param>
            /// <param name="content">SMS content</param>
            /// <param name="maxNumberOfMessages">Maximum no no messages to use before truncation of content</param>
            /// <returns>Number of messages remaining. -1 if an error occurred.</returns>
            public int Send(string to, string content, int maxNumberOfMessages)
            {
                int messagesRemaining;
                try
                {                
                    int messageLength = 160;
                    int length = messageLength * maxNumberOfMessages;
                    content = content.Substring(0, content.Length > length ? length : content.Length);
                    string completeUrl;
                    string urlEncodedContent = HttpUtility.UrlEncode(content);
                    completeUrl = String.Format("{0}send.php?u={1}&p={2}&s={3}&d={4}&m={5}",
                        Url, Login, Password, providerEnumToProviderString(Provider), to, urlEncodedContent);
                    string response = wget(completeUrl);
                    messagesRemaining = int.Parse(response);
                }
                catch (Exception Ex)
                {
                    messagesRemaining = -1;
                }
                return messagesRemaining;
            }
    
            private string wget(string url)
            {
                string result;
                try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
                    myRequest.Method = "GET";
    
                    WebResponse myResponse = myRequest.GetResponse();
                    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                    result = sr.ReadToEnd();
                    sr.Close();
                    myResponse.Close();
                }
                catch (Exception Ex)
                {
                    result = "-1";
                }
                return result;
            }
    
            private string providerEnumToProviderString(ProviderEnum pEnum)
            {
                string pString = "m";
                if (pEnum == ProviderEnum.METEOR) pString = "m";
                else if (pEnum == ProviderEnum.O2) pString = "o";
                else if (pEnum == ProviderEnum.VODAFONE) pString = "v";
                return pString;
            }
    
            public enum ProviderEnum
            {
                O2, VODAFONE, METEOR
            }
        }
    }
    


  • Closed Accounts Posts: 94 ✭✭Done and dusted


    Cheers :) I always like to see the src of .DLL's before I use them :D

    I may build a few apps such as Nofiying the admins in work of any application crashes, unexpected reboots, login etc if its cool to use this dll for that?

    Of course Ill pop the apps up here and give full credit :)


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Yup, use it for what you like.
    I'll just reiterate that it uses the cabaal.org/cabbage/ to send the texts, so anyone there could get your details if they wanted.


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    hi there. It's my script that's being used for this. If people are worried about sending their login details to my site you can of course put the scripts on your own site or i also have an exe written in vb6 that can communicate directly with the network site and anyone is free to get the code

    edit:@placebo, if you want a standalone text sender take a look at the link in my sig :) it uses the same interface as the dll


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Yup, cheers Sam.
    Any update on getting the meteor part working?


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    yep it's working again. The code's a mess because i wrote it in an hour just to get something working but i'm going to work on making it better over the next few days


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    I still get 'Could not connect to network site' from http://cabaal.org/cabbage/d.php


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    oh sorry i thought you were talking about the main script. I haven't got around to fixing the web based texter script yet


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Its working again, so thanks Sam.

    I've added new methods to allow you to send asynchronously. So instead of calling Send and waiting for the response you can call SendAsync and it will spawn a thread and let your code continue to execute straight away.

    eg.
    s.SendAsync("08512345678", "Sent asynchronously");
    

    You can also pass a function that will be called back when the SMS is send.
    Using anonymous function:
    s.SendAsync("08512345678", "Sent asynchronously",  delegate(int val) { Console.WriteLine("Number of remaining texts " + val); });
    

    Using normal function:
    // Define the function that you want to call back somewhere
    // Probably won't have to be static in your case.
    public static void CallMe(int x)
            {
                Console.WriteLine("I was called back: " + x);
            }
    
    
    .
    .
    .
    
    // Then call SendAsync like so:
    s.SendAsync("08512345678", "Sent asynchronously", new SMSSender.SendCompleteCallbackType(CallMe));
    

    DLL is in the same location.
    Should be backward compatible, but I haven't tested that. Let me know it if isn't.


    Source:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Net;
    using System.Web;
    using System.IO;
    using System.Threading;
    namespace NetSms
    {
        public class SMSSender
        {
            private string url;
            private string login;
            private string password;
            private ProviderEnum provider;
            /// <summary>
            /// Gets and sets the url of the cabaal php file locations
            /// Include training slash
            /// </summary>
            public string Url
            {
                get
                {
                    return url;
                }
                set
                {
                    url = value;
                }
            }
            /// <summary>
            /// Gets and sets the login string (eg. your telephone number)
            /// </summary>
            public string Login
            {
                get
                {
                    return login;
                }
                set
                {
                    login = value;
                }
            }
            /// <summary>
            /// Gets and sets the password string
            /// </summary>
            public string Password
            {
                get
                {
                    return password;
                }
                set
                {
                    password = value;
                }
            }
            /// <summary>
            /// Gets and sets the provider string (m (meteor), v (vodafone)m, o (o2)) 
            /// </summary>
            public ProviderEnum Provider
            {
                get
                {
                    return provider;
                }
                set
                {
                    provider = value;
                }
            }
    
            /// <summary>
            /// Creates SMSSender
            /// </summary>
            public SMSSender()
            {
                Url = "http://cabaal.org/cabbage/";
                Provider = ProviderEnum.METEOR;
            }
    
            /// <summary>
            /// Sends an SMS
            /// Ensure you have set Login, Password, Provider and optionally Url before calling this.
            /// </summary>
            /// <param name="to">telephone number to send to</param>
            /// <param name="content">SMS content</param>
            /// <param name="maxNumberOfMessages">Maximum no no messages to use before truncation of content</param>
            /// <returns>Number of messages remaining</returns>
            public int Send(string to, string content)
            {
                return Send(to, content, 1);
            }
            /// <summary>
            /// Sends an SMS
            /// Ensure you have set Login, Password, Provider and optionally Url before calling this.
            /// </summary>
            /// <param name="to">Telephone number to send to. Eg. 0851234567</param>
            /// <param name="content">SMS content</param>
            /// <param name="maxNumberOfMessages">Maximum no no messages to use before truncation of content</param>
            /// <returns>Number of messages remaining. -1 if an error occurred.</returns>
            public int Send(string to, string content, int maxNumberOfMessages)
            {
                int messagesRemaining;
                try
                {
                    int messageLength = 160;
                    int length = messageLength * maxNumberOfMessages;
                    content = content.Substring(0, content.Length > length ? length : content.Length);
                    string completeUrl;
                    string urlEncodedContent = HttpUtility.UrlEncode(content);
                    completeUrl = String.Format("{0}send.php?u={1}&p={2}&s={3}&d={4}&m={5}",
                        Url, Login, Password, providerEnumToProviderString(Provider), to, urlEncodedContent);
                    string response = wget(completeUrl);
                    messagesRemaining = int.Parse(response);
                }
                catch (Exception Ex)
                {
                    messagesRemaining = -1;
                }
                return messagesRemaining;
            }
    
            private string wget(string url)
            {
                string result;
                try
                {
                    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
                    myRequest.Method = "GET";
                    WebResponse myResponse = myRequest.GetResponse();
                    StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                    result = sr.ReadToEnd();
                    sr.Close();
                    myResponse.Close();
                }
                catch (Exception Ex)
                {
                    result = "-1";
                }
                return result;
            }
    
            private string providerEnumToProviderString(ProviderEnum pEnum)
            {
                string pString = "m";
                if (pEnum == ProviderEnum.METEOR) pString = "m";
                else if (pEnum == ProviderEnum.O2) pString = "o";
                else if (pEnum == ProviderEnum.VODAFONE) pString = "v";
                return pString;
            }
    
            public enum ProviderEnum
            {
                O2, VODAFONE, METEOR
            }
    
            public void SendAsync(string to, string content, SendCompleteCallbackType targetCallbackFn)
            {
                Thread t = new Thread(delegate() { aSendWorker(to, content, 1, targetCallbackFn); });
                t.Start();
            }
            public void SendAsync(string to, string content, int maxNumberOfMessages, SendCompleteCallbackType targetCallbackFn)
            {
                Thread t = new Thread(delegate() { aSendWorker(to, content, maxNumberOfMessages, targetCallbackFn); });
                t.Start();
            }
            public void SendAsync(string to, string content)
            {
                Thread t = new Thread(delegate() { aSendWorker(to, content, 1,  delegate(int val) { }); });
                t.Start();
            }
            public void SendAsync(string to, string content, int maxNumberOfMessages)
            {
                Thread t = new Thread(delegate() { aSendWorker(to, content, maxNumberOfMessages, delegate(int val) { }); });
                t.Start();
            }
    
            private void aSendWorker(string to, string content, int maxNumberOfMessages, SendCompleteCallbackType targetCallbackFn)
            {
                int val = Send(to, content, maxNumberOfMessages);
                targetCallbackFn(val);
            }
            public delegate void SendCompleteCallbackType(int val);
        }
    }
    


  • Closed Accounts Posts: 9 bzylg010


    Hi there, I am working on my FYP. It's about a robot patrol system, one feature about that is sms notification. The whole thing is based on VB6.0 and I wonder if I can get a copy of your VB6.0 sms sender source code. Cheers! ^_^


  • Closed Accounts Posts: 9 bzylg010


    Sam Vimes wrote: »
    hi there. It's my script that's being used for this. If people are worried about sending their login details to my site you can of course put the scripts on your own site or i also have an exe written in vb6 that can communicate directly with the network site and anyone is free to get the code

    edit:@placebo, if you want a standalone text sender take a look at the link in my sig :) it uses the same interface as the dll

    Hi there, I am working on my FYP. It's about a robot patrol system, one feature about that is sms notification. The whole thing is based on VB6.0 and I wonder if I can get a copy of your VB6.0 sms sender source code. Cheers! ^_^


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    bzylg010 wrote: »
    Hi there, I am working on my FYP. It's about a robot patrol system, one feature about that is sms notification. The whole thing is based on VB6.0 and I wonder if I can get a copy of your VB6.0 sms sender source code. Cheers! ^_^

    It's written in C# I'm afraid. If you use VB.NET then you can make use of the DLL in your application.

    Otherwise you could make your own code to send the sms. All you have to do is get your app to load a URL. You can into the cabaal site here http://cabaal.org/cabbage/newlogin.htm and send a few texts to work out the URL to use.


  • Advertisement
  • Closed Accounts Posts: 9 bzylg010


    It's written in C# I'm afraid. If you use VB.NET then you can make use of the DLL in your application.

    Otherwise you could make your own code to send the sms. All you have to do is get your app to load a URL. You can into the cabaal site here http://cabaal.org/cabbage/newlogin.htm and send a few texts to work out the URL to use.

    Thank you very much, I found that too just now.
    'http://cabaal.org/cabbage/d.php?u=[my.number]&p=[password]&s=v&ph=[his.number]&d=&m=[message]'

    But seems their system down, just give me an "Error. Msg not sent".

    So is my understanding wrong or the website's down?

    Thanks!


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Works for me. Make sure you have the s=* part send right.

    If you aren't vodafone don't use v. m=metoer. o=O2.


  • Closed Accounts Posts: 9 bzylg010


    Works for me. Make sure you have the s=* part send right.

    If you aren't vodafone don't use v. m=metoer. o=O2.

    Figured out the reason, message cant be shorter than 3 chars. And why the '*.php' in http://cabaal.org/cabbage/d.php changes all the time? Thanks!!!


  • Closed Accounts Posts: 9 bzylg010


    never mind, I just went crazy. Dont answer that silly thing. Thank you for all this help!!!


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    bzylg010 wrote: »
    Figured out the reason, message cant be shorter than 3 chars. And why the '*.php' in http://cabaal.org/cabbage/d.php changes all the time? Thanks!!!

    i'm not sure why you're pointing at d.php, you should be pointing at send.php.

    here's my code in vb6.0 for sending messages:
    Public Function sendMsg(url As String) As Integer  'send message using server
    
    
    On Error GoTo errSend
        sendMsg = -6
        Call URLEncode(url)                      
        Dim http As Object
        Set http = CreateObject("Microsoft.XmlHttp")
        http.open ("GET", url, False)
        http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
        http.send ("") 'you need the brackets for reasons i won't go into
        'DoEvents
        If IsNumeric(http.responseText) Then
            sendMsg = http.responseText
        Else
            sendMsg = -5
        End If
        
        Exit Function
    errSend:
        sendMsg = -6
    End Function
    

    set up the url as http://cabaal.org/cabbage/send.php?u=0871234567&p=password&s=s/v/m&d=0871234567&m=message


    i think you need to reference some libraries to use those functions and i can't remember which so here's the list of what i've referenced by clicking project->references:

    visual basic for application
    visual basic runtime objects and procedures
    visual basic objects and procedures
    ole automation
    microsoft scripting runtime
    microsoft xml, v5.0 <-most likely the needed one


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    bzylg010 wrote: »
    Hi there, I am working on my FYP. It's about a robot patrol system, one feature about that is sms notification. The whole thing is based on VB6.0 and I wonder if I can get a copy of your VB6.0 sms sender source code. Cheers! ^_^

    You can make the DLL COM visible if you have a default constructor and use REGASM to generate the COM entries correctly in the registry.

    This will allow you to call the DLL as a normal object within VB6


  • Moderators, Home & Garden Moderators, Regional Midwest Moderators, Regional West Moderators Posts: 16,724 Mod ✭✭✭✭yop


    Guys,
    I am looking for a solution like this for both VCalenders and WAP Push messages.

    Could this be tailored do you think?

    I downloaded a few solutions, all need a GSM modem or mobile handy.

    I need to A) the ability to send SMS, this suit brilliantly, B) Send VCalenders, C) Send a WAP Push message for a customer to download a little JAVA app.

    Using VB.NET as the body of my larger system, the A,B & C will be incorporated in this system.

    Thanks


  • Registered Users, Registered Users 2 Posts: 2,364 ✭✭✭Mr. Flibble


    Are VCalenders/WAP Push messages just SMSs of a particular format which the phone interputs? If not, then I don't think this will be of any use. It will only send a basic SMS and would be limited by the functionality of the cabbage web service that it uses.


  • Moderators, Home & Garden Moderators, Regional Midwest Moderators, Regional West Moderators Posts: 16,724 Mod ✭✭✭✭yop


    Are VCalenders/WAP Push messages just SMSs of a particular format which the phone interputs? If not, then I don't think this will be of any use. It will only send a basic SMS and would be limited by the functionality of the cabbage web service that it uses.

    Thats fair enough.

    Thanks


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 7,518 ✭✭✭matrim


    yop wrote: »
    Guys,
    I am looking for a solution like this for both VCalenders and WAP Push messages.

    Could this be tailored do you think?

    I downloaded a few solutions, all need a GSM modem or mobile handy.

    I need to A) the ability to send SMS, this suit brilliantly, B) Send VCalenders, C) Send a WAP Push message for a customer to download a little JAVA app.

    Using VB.NET as the body of my larger system, the A,B & C will be incorporated in this system.

    Thanks

    You could try something like clickatell (www.clickatell.com). You can buy SMS's off them and then use their API to send a text through their SMS gateway.

    I think they allow wap push \ vCards etc.

    There are a couple of other sites that allow this too but I can't remember the names off the top of my head


  • Closed Accounts Posts: 4 dananos


    Hi,

    You can try downloading this:

    http://www.freebiesms.co.uk/download/SmsSenderSample.zip

    It's an example of sending SMS via C# from a webservice

    Dan


  • Moderators, Home & Garden Moderators, Regional Midwest Moderators, Regional West Moderators Posts: 16,724 Mod ✭✭✭✭yop


    Thanks Dan,
    Will have a look


Advertisement