I still remember those days when mobile phones were just mobile phones. Nowadays, they are loaded with tons of hardware features that extend their use as full-blown life organizers and enterprise tools. As mobile device manufacturers find ingenious ways to squeeze in ever more hardware functionality, the .NET Compact Framework and other third-party vendors have been busy trying to write the software to keep up. Through Windows Mobile 6, a whole range of functionality has been added to let you, the developer, tap into the various hardware features of the mobile device.
Third-party libraries like the Smart Device Framework have also been active in this area, releasing classes and controls that make .NET Compact Framework development easier than ever. In this chapter, you will learn how to add the following functionalities to the sales force application:
As you are probably aware, Windows Mobile uses the integrated Outlook Mobile software to manage your tasks, appointments, e-mails, SMS, and MMS messages. Microsoft provides the Microsoft.WindowsMobile.PocketOutlook
namespace, which allows you to utilize Outlook Mobile to programmatically send an SMS or e-mail.
The POOM (Pocket Outlook Object Model) allows you to automate the Windows Mobile messaging application's UI. This means that you can use POOM to send SMS and e-mail messages, create tasks, iterate through your appointments, and so on.
There are two ways to include SMS- and e-mail-sending capability in your application. One way is to build your own UI to let the user key in his or her message and use POOM to programmatically send the message. Alternatively, you could also delegate this functionality to the default Windows Mobile Compose window (and, to make it more convenient for the end user, prefill some of the fields in this window with the minimum data required—such as the intended recipient of the message). Let's take a look at both approaches in the following sections:
Sending an SMS through POOM is straightforward. Before you can use POOM, however, you must first import a reference to the Microsoft.WindowsMobile.PocketOutlook
library.
All the code that you need to send an SMS is shown as follows:
using Microsoft.WindowsMobile.PocketOutlook; public void SendSMS(string phoneNumber, string message) { SmsMessage _msg; _msg = new SmsMessage(phoneNumber, message); _msg.Send(); } public static void main() { SendSMS("+6598532715","Hello world!"); }
You can send an e-mail through POOM using the EmailMessage
class. The code to do this is similarly straightforward.
public void SendEmail() { EmailMessage _em = new EmailMessage(); //Define recipients _em.To.Add(New Recipient("John Mayer", "[email protected]")); _em.To.Add(New Recipient("Ed Stables", "[email protected]")); //Define CC or BCC list, if any _em.CC.Add(New Recipient("Greg Yap", "[email protected]")); //Define attachments you can attach multiple files _em.Attachments.Add(New Attachment("C:documentscontract.docx")); _em.Attachments.Add(New Attachment("C:documentscontract2.docx")); //Define other e-mail attributes _em.Importance = Importance.High; _em.Sensitivity = Sensitivity.Confidential; //Define the main e-mail subject and body _em.Subject = "The contract documents you asked for"; _em.BodyText = "Hey guys, as requested..."; //Send out the e-mail using an e-mail account on Mobile Outlook _em.Send("AcmeSMTPAccount"); }
Outlook Mobile by default provides Compose windows that let you compose an SMS or e-mail message in Windows Mobile (accessible under the Messaging menu). These windows can be seen as follows:
Your application could use POOM to launch these windows (prefilled with some minimal data). For example, if you wanted to provide functionality to send an SMS using a phone number available in your application, you could launch the Compose Text Message window with the To phone number field filled in and the content of the SMS defaulted to some value. Let's see how this could be done in code:
SMSMessage _msg = new SMSMessage(); _msg.To.Add(New Recipient("Ed", "+6598532715")); _msg.Body = "This message was sent from CRMLive!"; MessagingApplication.DisplayComposeForm(_msg);
You could do the same thing with e-mails by creating an EmailMessage
object and feeding it to the same MessagingApplication.DisplayComposeForm()
function.
3.139.86.56