WP8.1StoreApp(WP8.1RT)---发送邮件和短信_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > WP8.1StoreApp(WP8.1RT)---发送邮件和短信

WP8.1StoreApp(WP8.1RT)---发送邮件和短信

 2014/4/19 3:36:14  刘白菜  博客园  我要评论(0)
  • 摘要:在WP7/8中,发送短信是利用了EmailComposeTask和SmsComposeTask来实现的。在WP8.1StoreApp中,原来的方式已经失效,采用了新的方法:ChatMessageManager和EmailManager管理和发送信息。简单使用:privateasyncvoidSendSmsTask(stringbody,stringphoneNum){varchatMessage=newWindows.ApplicationModel.Chat.ChatMessage()
  • 标签:邮件 发送邮件 APP

在WP7/8中,发送短信是利用了EmailComposeTask和SmsComposeTask来实现的。

在WP8.1 Store App中,原来的方式已经失效,采用了新的方法:ChatMessageManager和EmailManager管理和发送信息。

简单使用:

private async void SendSmsTask(string body,string phoneNum)
{
    var chatMessage = new Windows.ApplicationModel.Chat.ChatMessage();
    chatMessage.Body = body;
    chatMessage.Recipients.Add(phoneNum);
    await ChatMessageManager.ShowComposeSmsMessageAsync(chatMessage);
}
private async void SendEmailTask(string body, string emailAddress)
{
    var emailMessage = new EmailMessage();
    emailMessage.Body = body;
    emailMessage.To.Add(new EmailRecipient(emailAddress));
    await EmailManager.ShowComposeNewEmailAsync(emailMessage);
}

 

msdn的介绍:

private async void ComposeSms(Windows.ApplicationModel.Contacts.Contact recipient,string messageBody,StorageFile attachmentFile,string mimeType)
{
    var chatMessage = new Windows.ApplicationModel.Chat.ChatMessage();
    chatMessage.Body = messageBody;
 
    if (attachmentFile != null)
    {
        var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);
 
        var attachment = new Windows.ApplicationModel.Chat.ChatMessageAttachment(
            mimeType,
            stream);
 
        chatMessage.Attachments.Add(attachment);
    }
 
    var phone = recipient.Phones.FirstOrDefault<Windows.ApplicationModel.Contacts.ContactPhone>();
    if (phone != null)
    {
        chatMessage.Recipients.Add(phone.Number);
    }
    await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(chatMessage);
}
 
private async void ComposeEmail(Windows.ApplicationModel.Contacts.Contact recipient,string messageBody,StorageFile attachmentFile)
{
    var emailMessage = new Windows.ApplicationModel.Email.EmailMessage();
    emailMessage.Body = messageBody;
 
    if (attachmentFile != null)
    {
        var stream = Windows.Storage.Streams.RandomAccessStreamReference.CreateFromFile(attachmentFile);
 
        var attachment = new Windows.ApplicationModel.Email.EmailAttachment(
            attachmentFile.Name,
            stream);
 
        emailMessage.Attachments.Add(attachment);
    }
 
    var email = recipient.Emails.FirstOrDefault<Windows.ApplicationModel.Contacts.ContactEmail>();
    if (email != null)
    {
        var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address);
        emailMessage.To.Add(emailRecipient);
    }
 
    await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage);
 
}

原文:

http://blog.liubaicai.com/?p=300

 

 

 

发表评论
用户名: 匿名