Send SMS to Outlook Contact - A VSTO Outlook Add-in
Imagine you can send an SMS message to a mobile phone number of an Outlook contact directly from your Outlook. Despite there are some Outlook Add-ins those allow to do that, why don't build by your own. All you need are VSTO and GSM modem, either dedicated GSM modem or a mobile phone that can be connected via COM (using USB, Bluetooth, or Infrared).
Here are some capture how our add-in will look like.
Custom toolbar to connect to GSM modem and display SMS form
When you click GSM Modem button, GSM Modem form will be displayed. Fill the textfields and click connect, "Phone is connected" dialog will be shown if connection is successful.
Clicking Send SMS button will display SMS Form. Number will be filled automatically from Contact's mobile phone.
By double clicking to a contact in contact list, contact detail will be displayed. I add two controls to ribbon to connect to GSM modem. If connection has been made previously, it will not connect again. There is also a form region to send SMS directly from Contact detail.
GSM Communication
For GSM communication, I don't make it from the scratch. Instead, I use GSM Communication Library available at: http://www.scampers.org/steve/sms. Some basic knowledge about GSM Comm:
1. Make a connection to GSM modem device
public GsmCommMain GsmComm {set; get;}
public void Connect(int comPort, int baudRate, int timeout)
{ try
{ GsmComm = new GsmCommMain(comPort, baudRate, timeout);
GsmComm.PhoneConnected += new EventHandler(GsmComm_PhoneConnected);
GsmComm.PhoneDisconnected += new EventHandler(GsmComm_PhoneDisconnected);
GsmComm.Open();
}
catch (System.Exception ex)
{ MessageBox.Show(ex.Message);
}
}
void GsmComm_PhoneDisconnected(object sender, EventArgs e)
{ MessageBox.Show("Phone is disconnected");}
void GsmComm_PhoneConnected(object sender, EventArgs e)
{ MessageBox.Show("Phone is connected");}
2. Disconnect
public void Disconnect()
{ if (GsmComm != null && GsmComm.IsOpen())
{ GsmComm.PhoneConnected -= new EventHandler(GsmComm_PhoneConnected);
GsmComm.PhoneDisconnected -= new EventHandler(GsmComm_PhoneDisconnected);
GsmComm.Close();
}
}
3. Send Short Message
public void SendSms(String phoneNo, String msg)
{ if ((GsmComm == null) || (!GsmComm.IsOpen()))
{ MessageBox.Show("Phone is not connected"); return;
}
try
{ SmsSubmitPdu pdu = new SmsSubmitPdu(msg, phoneNo, String.Empty);
GsmComm.SendMessage(pdu);
}
catch (Exception ex)
{ MessageBox.Show(ex.Message);
}
}
The rest code are used for building Outlook Add-in, add custom toolbar, add custom ribbon, form region, and other Windows Forms. Complete code can be downloaded at: http://dycode.com/files/folders/codesamples/entry125.aspx
I make a screencast to show you how to build this add-in step by step.
http://images.soapbox.msn.com/flash/soapbox1_1.swf?c=v&v=c2985270-5ec6-412b-bf3b-32485adf428a
View original media here: http://video.msn.com/video.aspx?vid=c2985270-5ec6-412b-bf3b-32485adf428a
You can download good quality video by following this link: http://cid-0cbe0e395b6f9491.skydrive.live.com/self.aspx/Public/SendSMSOutlookAddIn.zip
That's it for now. Enjoy.