Email, SMS, PIM - ThS. Trần Minh Triết

ppt 20 trang phuongnguyen 2320
Bạn đang xem tài liệu "Email, SMS, PIM - ThS. Trần Minh Triết", để tải tài liệu gốc về máy bạn click vào nút DOWNLOAD ở trên

Tài liệu đính kèm:

  • pptemail_sms_pim_ths_tran_minh_triet.ppt

Nội dung text: Email, SMS, PIM - ThS. Trần Minh Triết

  1. Đại học Khoa học Tự nhiên, ĐHQG-HCM Khoa Công Nghệ Thông Tin Bài 6: Email, SMS, PIM ThS. Trần Minh Triết 1
  2. Tham khảo Professional Microsoft Smartphone Programming, Baijian Yang, Pei Zhengand, Lionel M. Ni Wrox Press 2007 (518 pages), ISBN:9780471762935 Chapter 8. E-mail, SMS, and PIM Data 2
  3. Pocket Outlook Object Model (POOM) Pocket Outlook Object Model (POOM): tập hợp các class cung cấp các API để thao tác với Microsoft Access trên thiết bị sử dụng các hệ điều hành nhóm Windows CE. POOM là tập con của class trong mô hình đối tượng của Outlook trên desktop Xử lý email, SMS, thông tin PIM (personal information manager) 3
  4. SDK và namespace Cài đặt thêm Windows Mobile 5.0 for Smartphone SDK (~77MB) Namespace: Microsoft.WindowsMobile.PocketOutlook 4
  5. Microsoft.WindowsMobile.PocketOutlook 5
  6. Các bước sử dụng Microsoft.WindowsMobile.PocketOutlook Tạo session Outlook mới: OutlookSession aSession = new OutlookSession(); Truy cập các đối tượng PIM: Các property cho phép gửi e-mail e-mail, SMS message, thao tác trên dữ liệu PIM: Appointments Contacts Tasks EmailAccounts SmsAccount Chấm dứt session Outlook (bắt buộc vì không thể được gabage collector tự động xử lý) aSession.Dispose(); 6
  7. Ví dụ TaskCollection taskItems = aSession.Tasks.Items; foreach (Task t in taskItems) { Messagebox.Show(t.subject); } 7
  8. Tạo email Tạo session mới OutlookSession aSession = new OutlookSession(); Chọn sử dụng 1 account email đã có EmailAccount anEmailAcct = aSession.EmailAccounts[1]; hoặc EmailAccount anEmailAcct = aSession.EmailAccounts["IMAP4"]; 8
  9. Tạo email Xác định người nhận Recipient recv = new Recipient("FirtName LastName", "FLastName@somewhere.com"); Tạo email mới EmailMessage mesg = new EmailMessage(); mesg.To.Add(recv); mesg.Subject = "Hello"; mesg.BodyText = "Dear readers, we hope you enjoy learning Smartphone programming"; anEmailAcct.Send(mesg); 9
  10. Tạo email có attachment // Create a new Select Picture dialog box SelectPictureDialog picDlg = new SelectPictureDialog(); picDlg.InitialDirectory = @"\Images"; // Do not forward // a Digital Rights Management protected file picDlg.ShowForwardLockedContent = false; // Get the dialog result DialogResult result = picDlg.ShowDialog(); 10
  11. Tạo email có attachment //Create a new email message EmailMessage mesg = new EmailMessage(); mesg.Subject = "Email with Picture Attachment"; mesg.BodyText = "Open the attachment. No virus"; //Create and add a new recipient Recipient resv = new Recipient("John Doe","JDoe@somewhere.com"); mesg.To.Add(resv); 11
  12. Tạo email có attachment //Add the picture to the attachment Attachment picture = new Attachment (picDlg.FileName); mesg.Attachments.Add(picture); //Use the default email account EmailAccount myEmail = aSession.EmailAccounts[0]; //Display the email compose form MessagingApplication.DisplayComposeForm(myEmail,mesg); 12
  13. Thao tác với thông tin PIM OutlookSession CalSess = new OutlookSession(); Cách truy cập thông tin Appointment: AppointmentCollection CalCol = CalSess.Appointments.Items; Cách truy cập thông tin Task: TaskCollection TCol = CalSess.Tasks.Items; Cách truy cập thông tin Contact: ContactCollection TCol = CalSess.Contacts.Items; 13
  14. Ví dụ //Establish a new Outlook session OutlookSession CalSess = new OutlookSession(); //Get the collection of appointments by calling outlookSession.Appointments.Items AppointmentCollection CalCol = CalSess.Appointments.Items; 14
  15. Ví dụ //Add each appointment to the ListView foreach (Appointment apt in CalCol) { //Create one new ListView object for each appointment ListViewItem aLVItem = new ListViewItem(); //Make the appointment date the text property of this ListView aLVItem.Text = apt.Start.Date.ToString(); //Make other appointment property as the subitem aLVItem.SubItems.Add(apt.Subject); //You can also add a field for the appointment location aLVItem.SubItems.Add(apt.Location); //Add ListViewItem to the ListView CalView.Items.Add(aLVItem); } 15
  16. Chọn lọc thông tin string query = "[Categories] == wrox"; AppointmentCollection wroxAppt = aOutlookSession.Appointment.Items.restrict(query); Lưu ý: phép so sánh Ball State University"; Những appointment item không có thông tin Location cũng bị loại bỏ!!! 16
  17. Gửi SMS OutlookSession aSession = new OutlookSession(); SmsMessage sendMsg = new SmsMessage("18664365702", "Vote to Idol #2"); aSession.SmsAccount.Send(sendMsg); aSession.Dispose(); Account nào??? 17
  18. Gửi SMS SmsMessage sendMsg = new SmsMessage(); Recipient recv = new Recipient("18664365702"); sendMsg.Body = "Vote to Idol #2"; sendMsg.To.Add (recv); MessagingApplication.DisplayComposeForm(sendMsg) 18
  19. Nhận SMS using Microsoft.WindowsMobile.PocketOutlook.MessageInterception; msginterceptor = new MessageInterceptor(); msginterceptor.InterceptionAction = InterceptionAction.NotifyAndDelete; // Notify msginterceptor.MessageReceived += new MessageInterceptorEventHandler(msginterceptor_MessageReceived); 19
  20. Nhận SMS //Handling received message void msginterceptor_MessageReceived(object sender, MessageInterceptorEventArgs e) { SmsMessage smsMsg = (SmsMessage)e.Message; string fullText = "Message From: “+smsMsg.From.Name; fullText += (" at "+ smsMsg.Received.TimeOfDay.ToString()); fullText += (" and the message is: "+smsMsg.Body); MessageBox.Show(fullText, "New Text Message !"); } 20