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


    在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://www.liubaicai.net/?p=300

     

  • 相关阅读:
    课堂测试-文本操作
    异常的总结
    动手动脑实验-异常
    从小工到专家-读后感3
    从小工到专家-读后感2
    从小工到专家-读后感1
    构建之法读书笔记(一)
    2.12日总结
    BaseAdapter的使用
    Activity之Bundle的使用
  • 原文地址:https://www.cnblogs.com/liubaicai/p/3671435.html
Copyright © 2020-2023  润新知