SMS Messages with Windows Mobile 5.0

Published Thu, Jan 25 2007 2:40 | William

A while ago, I was playing around creating a bot, a Snarkier version of the Mobile Secretary Application .  Well, it was late and I got sloppy. So basically, my little app sent out a text message to everyone on one of my company's Outlook distribution lists. I learned a lot that night.

So you've always been able to send SMS messages with Smartphone, but it's a lot easier now.  Sending them isn't a big deal though. The cool thing is intercepting them.  To that end, the Message Interceptor class makes it quite easy:

  • Create a module level variable (or whatever scope you need it).

      private MessageInterceptor Interceptor;

  • Instantiate it in the constructor

      Interceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete, false);

  • Specify a InterceptionAction property. (Notify or NotifyAndDelete) - those should be self explanatory [See above]
  • Specify if you want it to use the Form's thread (a must if you want to update the UI) [see above]
  • Wire up a handler.

Interceptor.MessageReceived +=new MessageInterceptorEventHandler(Interceptor_MessageReceived);

  • Cast the e.Message object in the handler as a SmsMessage and use accordingly

 

void Interceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)

{

   SmsMessage IncomingMessage = (e.Message as SmsMessage);

   String[] ImportantStuff = new String[]{"Dog pooping",

                                          "Vista Launch",

                                          "Would you care to explain THIS?",

                                          "Vicodin ES",

                                          "Camel Toe",

                                          "Kim",

                                          "Mom",

                                           "EDC"};

foreach(String s in ImportantStuff){

if(IncomingMessage.Body.IndexOf(s)> -1){

SmsMessage OutgoingMessage = new SmsMessage(e.Message.From.Address, "This is the Cuckoobot, I'm handling Bill's messages, he'll be in touch shortly");

OutgoingMessage.Send();//Yes, I know this isn't optimal - it's demo code.

}

else{

SmsMessage OutgoingMessage = new SmsMessage(e.Message.From.Address, "This is the Cuckoobot. Your message isn't important and will have to wait.");

OutgoingMessage.Send();
}
}
}

Comments

# Be Geek My Friend said on January 25, 2007 12:43 AM:

Hoy en cosas interesantes: Enviar SMS desde Mobile 5 con .Net, Microsoft e IBM, HP y Linux, Restaura

Search

This Blog

Tags

Community

Archives

News

My other sites

Cool Stuff

Book Stuff

Security

ORM

Data Access

Funny Stuff

Compact Framework Stuff

Web Casts

My KnowledgeBase Articles

My MVP Profile

Design Patterns

Performance

Debugging

Remoting

My Fellow Authors

My Books

LINQ

Misc

Speech

Syndication

Email Notifications