Chapter 5. Building Integrated Services

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:

  • Placing phone calls and sending SMS messages/e-mails to a lead directly
  • Detecting and logging all incoming and outgoing communication (SMS messages and phone calls)
  • Using the Bluetooth and Infrared capabilities of your mobile device to transfer a lead account between devices
  • Capturing a customer's signature

Sending SMS and e-mail from your 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 SMS and e-mail directly through code

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.

Sending SMS and e-mail directly through code

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");
}

Delegating to the default Windows Mobile Compose UI

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:

Delegating to the default Windows Mobile Compose UIPOOMused, for sending e-mail

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.86.56