启动器和选择器学习-----(4)选择器之电子邮件
现在的手机基本都支持电子邮件的收发,当然我们的Windows Phone也是支持的。Windows Phone可以支持传统的电子邮件服务,如POP3(Post Office Protocol,邮件处理协议),IMAP(Inernet Message Access Protocol,互联网信息访问协议)以及SMTP(Simple Mail Transfer Protocol,简单邮件传输协议),此外,还可以与Exchange服务器进行同步。
1、SaveEmailAddressTask
使用SaveEmailAddressTask可以向Windows Phone联系人列表中的联系人添加电子邮件地址。
1 public partial class ChooserTask : PhoneApplicationPage 2 { 3 private SaveEmailAddressTask nSaveEmailAddress = new SaveEmailAddressTask(); 4 5 public ChooserTask() 6 { 7 InitializeComponent(); 8 9 nSaveEmailAddress.Completed += new EventHandler<TaskEventArgs>(nSaveEmailAddress_Completed); 10 } 11 12 void nSaveEmailAddress_Completed(object sender, TaskEventArgs e) 13 { 14 if (e.TaskResult == TaskResult.OK) 15 MessageBox.Show("电子邮件地址已经保存!"); 16 else 17 MessageBox.Show("电子邮件地址没有保存!"); 18 } 19 20 private void Button_Click_4(object sender, RoutedEventArgs e) 21 { 22 if (!string.IsNullOrEmpty(EmailAddress.Text)) 23 { 24 nSaveEmailAddress.Email = EmailAddress.Text; 25 nSaveEmailAddress.Show(); 26 } 27 } 28 }
2、EmailAddressChooserTask
EmailAddressChooserTask也是利用Contact Selector来返回电子邮件地址,与上一篇PhoneNumberChooserTask相同。
1 public partial class ChooserTask : PhoneApplicationPage 2 { 3 private EmailAddressChooserTask nEmailAddressChooser = new EmailAddressChooserTask(); 4 5 public ChooserTask() 6 { 7 InitializeComponent(); 8 9 nEmailAddressChooser.Completed += new EventHandler<EmailResult>(nEmailAddressChooser_Completed); 10 } 11 12 void nEmailAddressChooser_Completed(object sender, EmailResult e) 13 { 14 if (e.TaskResult == TaskResult.OK) 15 { 16 EmailAddressChooser.Text = e.Email; 17 } 18 } 19 20 private void Button_Click_5(object sender, RoutedEventArgs e) 21 { 22 nEmailAddressChooser.Show(); 23 } 24 }
在返回的EmailResult中还有一个DisplayName属性是返回电子邮件所有人姓名。
3、EmailComposeTask
EmailComposeTask通过设置To、Subjeck以及Body字段来生产一封预先设置好的电子邮件。
1 private void Button_Click_6(object sender, RoutedEventArgs e) 2 { 3 if (!string.IsNullOrEmpty(EmailAddressChooser.Text)) 4 { 5 EmailComposeTask nSendEmail = new EmailComposeTask(); 6 nSendEmail.To = EmailAddressChooser.Text; 7 nSendEmail.Subject = "我们一起参加卤面比赛吧"; 8 nSendEmail.Body = "参加比赛一起赢取800哦。"; 9 nSendEmail.Show(); 10 } 11 }