Oct 5 2009

Send Instant Message Notifications from your .Net Applications!

Category: amilsark @ 21:44
 
I’ve been interested in figuring out how to notify someone of an interesting application event by other means than just email.
This led me to find the MSNPSharp .Net Instant Messaging Library.  This library works with the MSN Instant Messaging Protocol.
 
Here are some features of the current version (2.5.7 with 3.0 coming out Fall 2009) – borrowed from the MSNPSharp Google code site (http://code.google.com/p/msnp-sharp/)
 

Features

The library currently supports the following features:

Messaging
Address Book
Roaming Profile
Nameserver(NS) and Switchboard(SB)
  • Signing in from multiple places (MPOP)
  • Support for bots (Provisioned_Accounts)
  • Hotmail mailbox status
  • Notifications of new mail
  • Setting presence status
  • Request or receive conversations
  • Multiple users in one conversation
  • File transfers
  • P2P framework support
  • Flexible tracing of warnings and errors
  • Proxy support and custom servers
 
 
 

How I Use It:

 
I implemented a simple ‘SendIM’ method as part of a Notification class.  This will simply connect to the MSN service with my IM account credentials and then
send an instant message with whatever text we choose.   If you noticed in the features list of this library, it can do offline messaging.  I’m not sure exactly how that works yet,
but it is worth understanding a little more. 
 
 

Download the binaries from http://code.google.com/p/msnp-sharp/.
Add a reference in your project to the MSNPSharp library.
 
Follow the below code to create a one way Instant message to the email address ‘contact’ you pass in.  The account you use
must be a valid account with live.com or hotmail.
 
I’ve found that we need the Thread.Sleep  in order to give it time to connect or else a null reference exception is thrown on the
conv.Switchboard.SendTextMessage(message) line.
 
   1: public void SendIM(string contact)
   2:         {
   3:            var  messenger = new Messenger();  
   4:             var message = new TextMessage("This works!! Give Andy a dollar... Now please..");
   5:             messenger.Credentials.Account = "youraccountemailaddress";
   6:             messenger.Credentials.Password = "yourpassword";
   7:             messenger.Nameserver.BotMode = true;
   8:             messenger.Nameserver.AutoSynchronize = false;
   9:             messenger.Connect();
  10:             System.Threading.Thread.Sleep(5000);
  11:  
  12:             try
  13:             {
  14:                 var conv = messenger.CreateConversation();
  15:                 conv.Switchboard.Invite(contact);
  16:                 System.Threading.Thread.Sleep(5000);
  17:                 conv.Switchboard.SendTextMessage(message);
  18:             }
  19:             catch(NullReferenceException nullex)
  20:             {
  21:                  //fall back email or logging   
  22:             }
  23:             catch(Exception ex)
  24:             {
  25:                 //fall back email or logging
  26:             }
  27:  
  28:         }

 

If you have anymore experience with this library or Instant message protocol please comment and share any gotchas or ideas you might have that might help myself and the community.

Tags: , , , ,

Comments

1.
PK Australia says:

Hi Andrew - there's absolutely NO examples out on the net about how to use this library Frown

I'm so stoked I stumbled across this post.

Firstly, u need to change the code so that u wire up a SIGNON event. Signing in takes around 3-4 seconds. So by forcing your thread to sleep, this in effect to allowing the signon to occur.

If you do this.. u can drop your thread sleeping...

messenger.Nameserver.SignedIn += new EventHandler<EventArgs>(Nameserver_SignedIn);
// If u want to handle auth errors, then add an event for that, also.
// _messenger.Nameserver.AuthenticationError += new EventHandler<ExceptionEventArgs>(Nameserver_AuthenticationError);
messenger.Connect();

...

void Nameserver_SignedIn(object sender, EventArgs e)
{
   // create the conversation, send message, etc.
}

---

Now, with your sample code, though. I can't create a Contact Frown The constructor for a Contect (with the latest code on their site) doesn't allow an email address to be added. So i have no idea how to create one ... and as such .. i can't continue Frown

Can u have a look / update your post?

-PK-

2.
Darcy Heidtman United States says:

haha … the one who is posting the comments  <a href="hride.com/.../">credit rewards cards</a>

3.
Marco Denholm United States says:

I'm a big blog enthusiast and with so many blogs on the internet now, very few stand out. This blog caught my eye and I thought that I would post to let you know that.

4.
Air Jordan Shoes United States says:

I sort of found this blog by mistake, but your blog caught my eye and I thought that I would post to let you know that I like it.

5.
Financial Blog United States says:

Hello there, thanks for this great article

6.
Elise United States says:

Can you tell me the name of the theme your blog is running? It looks kinda nice.

7.
Computer News United States says:

I have an old computer and I'm looking for articles to optimize it'll be a great computer.

8.
Mack Oneill United States says:

it's probably a pretty fair piece of change, all of it spent here in the US. i would say that's exactly the type of stimulus rhinebeck's economy could use.<a href=”http://www.ebulletproofvest.com”>bullet vest</a>

9.
Maxie Dautremont United States says:

Just wanted to give you a shout from the valley of the sun, great information. <a href=”http://www.ebulletproofvest.com”>armor vest</a>

10.
joey Singapore says:

i love your blog

11.
Consignment United States says:

I have been surfing online more than three hours today, yet I never found any interesting article like yours. It's pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the internet will be much more useful than ever before.

12.
scrapeboxuser United States says:

All I can say is... please write more. OMG, it seems as though I watched a video instead of reading an article...it's so apparent. You totally know what you're writing about. My thought was,  why waste your intelligence on blog articles when you could be authoring books? Think about it. You're very good at what you do. WORD!

13.
North American Bancard United States says:

Hello,
I don't agree with your post however there are some parts I never thought of before.  I like the theme you use with your site.

14.
get a ged United States says:

Thanks for making the sincere attempt to discuss this. I feel fairly strong about it and would like to read more. If it's allright, as you learn more in depth knowledge, would you mind writing more posts similar to this one with more information? It would be so helpful and useful for me and my colleagues.

15.
503296-B21 United States says:

I am going to reccomend your Blog to various associates of mine, I think you are definately on the right track

16.
oxx radio United States says:

Thank you for the post. I almost passed your website up in Bing but now I'm glad I checked it out and got to go through it. I'm definitely a little better informed now. I'll be sharing your site with some other people I know. They'll get a kick out of what I just read too. LOL. --Wreaf

17.
link directory United States says:

Holly smokes! I must say, your blog has to be one of the most well written blogs that I have read in a long time.What I wouldn't give to be able to create posts that are as fascinating| as yours. I think I'll have to continue reading your articles and pray that some day I can write on a topic with as much knowledge as you have! Bravo!!

18.
Samudra United States says:

Hrmm that was weird, my comment got eaten. Anyway I wanted to say that it's nice to know that someone else also mentioned this as I had trouble finding the same info elsewhere. This was the first place that told me the answer. Thanks.

19.
Sueann Lexer United States says:

It's wonderful to locate great posts like this a single. Thank you!

20.
Gratispoker United States says:

I have played for some Times in the 888 Gratis Poker one Time Played and Win that's funny.

21.
click earn money United States says:

Thanks for the great information.

22.
Air Jordan 5 United States says:

I like your professional looking blog. It is very neat and tidy.

23.
buy cars in usa Poland says:

good blog love this stuff

24.
Small Business Payroll Software United States says:

Greeting.  Neat template on your blog.  Want to exchange links?

25.
flip ultrahd camcorder United States says:

I reckon the information described in your post is actually excellent. I've been working on a preliminary research project on this topic and your article really assisted with a number of concerns that I had. I am writing a term paper for college and I?m currently following 65 blogs for review.

26.
earn cash online United States says:

Hello, I'm a college English student and I'm learning a lot about writing by reviewing blogs. I really enjoy your style of writing. It's simple to understand but with excellent details. Your vocabulary makes it enjoyable to read and understand. That's a huge segment of writing. Your followers have to be able to understand what you're conveying to them and it has to be engaging. You need to challenge your readers, so they will come back again. You do a good job with all of these aspects. Thank you!

27.
Isagenix United States says:

Awesome! Thank you for sharing.

28.
Porter-Cable Battery United States says:

Do you like running Blogengine?  If I might --perhaps you should consider adding a few videos.  I dont mean to disrespect what you've done here; its very enlightening, for sure.  But, I think would respond to it more positively if you could add something flashy to your posts.  Keep it up, but put a little more into it next time.

29.
insanity dvd United States says:

A great method to lose fat is following a great fitness routine along with a sensible diet plan. It's that basic.

30.
Towing Silver Spring United Kingdom says:

Very informative post I enjoyed reading it and am trying to absorb all the information.

31.
Jason Mazzawi United States says:

It sounds like you're creating problems yourself by trying to solve this issue instead of looking at why their is a problem in the first place  

32.
Single Mother Assistance United States says:

Nice information, many thanks to the author. It is incomprehensible to me now, but in general, the usefulness and significance is overwhelming. Thanks again and good luck!

33.
Voip Calls United States says:

Wonderful blog! I saw it at Yahoo and I must say that entries are well thought of. I will be coming back to see more posts soon.

34.
Cristobal Jaimes United States says:

I need this article to complete my assignment in the college, and it has same topic with your article.

35.
Pozycjonowanie Warszawa United States says:

I fully agree with author opinion.

36.
Brandon Jutras United States says:

I Completely recognise what your position in this matter is. Even if I should disagree on a number of the finer points, I feel you did a remarkable job explaining it. Certainly beats the need to research it by myself. Appreciate it.

37.
Swimming Tips United States says:

Wow!  Thanks for sharing.

38.
article directory United States says:

You can have quite a bit of success posting content to article directories.  I've easily triple traffic.

39.
free xbox kinect United States says:

not going around anybody or not residing life. Why would anyone want to avoid it? It only makes you improve and become much better.

40.
Towing Provo United Kingdom says:

The great subject that you should take is that this post is a very reliable one; its has are sure enough and every dealings will be done in the right manner.

41.
Towing Salt Lake City United Kingdom says:

I am definitely a lot more informed now. I will be recommending your site to some friends of mine.

42.
Towing Sandy United Kingdom says:

There is obviously a lot to know about this. I think you made some good points in Features also.

43.
heated gears United States says:

How do I begin a weblog? I just got a new account on Yahoo but don't see exactly where to begin composing.?

44.
Jailbreak Apps United States says:

I am absolutely fascinated at how interesting the stuff is on this web page. I have saved this page and I truly intend on visiting the site in the upcoming days. Great job keep up the fantastic work!

45.
Accounting Software Download United States says:

Buck up!  Things will be better soon.

46.
ÿþt United States says:

Hey im from germany and my english isnt that good, but i was able to understand every single word of your post. Im searching english blogs to improve my english skills and im very euphoric to finally find a journal, which speakes clear and structured english that i can translate. Thanks from Germany!

47.
Engelhard Silver Bars United States says:

The post has been excellent and I have referred it to many of my friends. I honor for the work that you have done. Thank you once again.

48.
international VOIP United States says:

Thanks for this insightful post. The info I have gained from your blog is truly encouraging

49.
free article submission and press releases directory United States says:

Making use of article directories makes for a good way to get more visitors to your website. While

50.
sex cam United States says:

adding this info to my blog if thats ok dude.

51.
chat nude United States says:

You really know your stuff... Keep up the good work!

52.
College Student Loan Consolidation United States says:

Couldn't be written any better. Reading this post reminds me of my old room mate! He always kept talking about this. I will forward this article to him. Pretty sure he will have a good read. Thanks for sharing!

53.
brand consultants United States says:

Great! this is nice article. Thank you for sharing.

54.
Towing Camden NJ United States says:

I needed to take just a minute and say thanks for writing about this. This particular topic has been on my mind these days; therefore I very much loved this post!

55.
Towing Cambridge MA United States says:

The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

57.
discount viagra United States says:

Well your post is spot on. I've found the cheapest viagra prices on pharmacyescrow.com's website.

58.
Consignment United States says:

I dont know who you think you are, but youre just blowing smoke out your ears.  Nothing youre saying makes sense and its all a bunch of immature ranting.  If you want people to get behind your blog, you should at the very least learn a little something about what youre talking about!

59.
free article submission and press releases directory United States says:

I'm tired of most of these article directories.  I'm looking for a list of article directories that instantaneously takes articles.

60.
Jonas Cirullo United States says:

I really like what you have posted here, it is a very well written and great article that gets right to the point. You could use a little reworking of the blog layout though, but the design is overall very nice. Great job, Thanks!

61.
Surround Systeme United States says:

Hello, i am from turkey so my english knowledge isnt that amazing. Please dont blame me. I try to read online journals to make my english better and say that your blog was perfect readable for me, because the english is really great and all the article are perfect readable. I will come back, to improve my english even more. Thanks a lot Smile

62.
Peggy Zorens Germany says:

Great Information, thanks for the great Article. Really great topic to write about on my Blog. I might make a link from another Blog. <A href="abbeyeyedoctors.ca">Optometrists</A>

63.
Brain Exercises United States says:

Hey.  Nice blog.  Mind if I link to it?

64.
how to quit smoking United States says:

A great method is to first think off and list down all the benefits or reasons why quitting should be done. Just as they say: if there is a will there is a way. Listing things would help motivate you and clarify why you need to do it.

65.
beat making software United States says:

Create about current trends and latest technology.

66.
duit internet Belgium says:

The good information and quality article.
Thanks to share the great article to us and you make a deeper reseach before writting the article.  
This is awesome jobs and efforts.
Can you give more article in your future post to share with us.

67.
teva mens brown suede dozer sandal United States says:

The price difference would need to be at least $30-50 far more affordable. By ordering on the web, you’re likely to be charged $10 shipping anyway, so usually I just acquire it at the shop. I’m okay with wasting a salesclerk’s time for one or two pairs of shoes, but for an hour? That is certainly certainly definitely selfish. Giving your good buddy the benefit on the doubt though, I’m certain it wasn’t her goal to go and waste a salesclerk’s time. She possibly didn’t even believe about it.

68.
teva mens brown suede dozer sandal United States says:

V – obvious from the comments thus far. I know that things like that get even trickier when you can find cultural differences from one location/country to another. You can find places where animals are cherished in one country that are seen as food in others, (Cattle, dogs, horses). So I didn’t realize that there were such strong feelings on this one, since I do not really encounter kangaroo outside of nature preserves like the San Diego wild animal park. I really feel it comes down to having as much information as feasible so that each individual can make the finest, informed, choices that they're comfortable with.

69.
African American Art United States says:

Most African-American artists market and exhibit in the African-American community. Successful Black art festivals and expos, where artists sell and exhibit, recognize the importance of marketing to this special community. It is in this community where the strength and the value of African-American art begins. It is this community that has provided the foundation for the Blackstream Renaissance. Read more - <a href="http://www.octobergallery.com">http://www.octobergallery.com</a>

70.
Web Based Accounting Software United States says:

Mah zeh?  Lamadeti evrit b'universite, tov mi'ode?

71.
African American News United States says:

Most African-American artists market and exhibit in the African-American community. Successful Black art festivals and expos, where artists sell and exhibit, recognize the importance of marketing to this special community. It is in this community where the strength and the value of African-American art begins. It is this community that has provided the foundation for the Blackstream Renaissance. Read more - http://www.octobergallery.com

72.
Beryl Platts credito United States says:

I was searching in the web for this in a while and found also other resources on the subject. However i must admit that you have made your point about it and i enjoyed your point of view. thanks for sharing.

73.
refurbished garmin United States says:

I have been reading your entries during my lunch break, and I have to admit the entire article has been very enlightening and very well written. I thought I would let you know that for some reason this blog does not display well in IE 8. I wish Microsoft would stop upgrading their software. I have a question for you. Do you mind exchanging blog roll links? That would be really neat!

74.
Tennis Ball Machines United States says:

Your post has really explained this topic very well. I will come around your forum more often!

76.
Roger Crose United States says:

i thought this was a really great post to read.  i'll check back for new posts by you!

77.
Limited Company United States says:

Hope they get out before christmas.

78.
cream overmantle mirror United States says:

Intimately, the article is in reality the most excellent on this precious topic. I agree with your conclusions and will thirstily look forward to your coming updates. Simply just saying thanks will certainly not simply just be enough, for the phenomenal lucidity in your writing. I will at once grab your rss feed to stay informed of any updates. Fabulous work and also much success in your business dealings!

79.
Janie United States says:

Merely want to say your article is striking. The lucidity in your post is simply spectacular and i can assume you are an expert on this field. Well with your permission allow me to grab your rss feed to keep up to date with incoming post. Thanks a million and please keep up the gratifying work.

80.
nanny cams United States says:

Your post has really explained this topic just the way i wanted to hear it. I will come around your blog more often!

81.
Manuel Brannock United States says:

Hey, great blog you have here, think I came across it on Google but i'm not sure now...anyway, I'll check back again!

83.
sizzlinghot United States says:

I also read a lot of blogs everyday. I cant even recall all of them, but there are also favorite blogs of mine. Your compilation is very nice, I want to compile mine also if I could have the time. Its so nice to see your article.

84.
teva mens brown suede dozer sandal United States says:

Personally, I’m glad there is certainly certainly a forum here for everyone to share their opinions, even if they are polarizing. I ,for one, have been enlightened by the comments, especially the ones produced by Gracia and Galligator. I had no idea the kangaroo population was so strong in Australia and a great deal like Galligator, now find myself open to the idea of kangaroo hide so long as it is done in a humane fashion & preserves the animal food chain. Thank you for educating my thinking.

85.
Indian Travel Plan United Kingdom says:

great page thanks for writing this.

86.
Jordan Shoes United States says:

I appreciate you taking the time to write about this. I am excited about the opportunity to read more of your well written topics. <a href="http://www.allsportshoes.com">Cheap Jordans</a> and <a href="www.allsportshoes.com/152-rare-jordans">Jordan Shoes</a>

87.
chat nude United States says:

You may have not intended to do so, but I think you have managed to express the state of mind that a lot of people are in. The sense of wanting to help, but not knowing how or where, is something a lot of us are going through.

88.
camgirls United States says:

The blog was absolutely fantastic! Lots of great information and inspiration, both of which we all need!

89.
Burton Haynes United States says:

Valuable material provided I'm quite pleased to go through this particular article..many thanks for presenting people nice tips.Fantastic walk-through. I enjoy this kind of blog post.

90.
Vilma Zuanich United States says:

Hi 1st time jumped right here on your website, founde on ASK.

91.
making home affordable United States says:

Of course, what an excellent web website and advisory posts, Can I add backlink - import your rss feed? Large thanks for that useful info i discovered on Har människorna blivit tokiga?.<br>

Add comment




  Country flag

biuquote
  • Comment
  • Preview
Loading