Thứ Tư, 26 tháng 2, 2014

Tài liệu Email, SMS, PIM docx

1
Bài 6: Email, SMS, PIM
Bài 6: Email, SMS, PIM
ThS. Trần Minh Triết
Đại học Khoa học Tự nhiên, ĐHQG-HCM
Khoa Công Nghệ Thông Tin
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
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)
4
SDK và namespace
Cài đặt thêm
Windows Mobile 5.0 for Smartphone SDK
(~77MB)
Namespace:
Microsoft.WindowsMobile.PocketOutlook
5
Microsoft.WindowsMobile.PocketOutlook
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();
7
Ví dụ
TaskCollection taskItems = aSession.Tasks.Items;
foreach (Task t in taskItems)
{
Messagebox.Show(t.subject);
}
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"];
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);
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();
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);
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);
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;
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;

Không có nhận xét nào:

Đăng nhận xét