zoukankan      html  css  js  c++  java
  • 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

     

  • 相关阅读:
    directUI
    PyLucene测试成功
    MFC笔记(1)CPaintDC, CClientDC
    sprintf缓冲区溢出
    2.5 攻击示例:对Microsoft C++编译器的攻击 ZZ
    C++笔记(3)类中与类外的运算符重载
    C++笔记(2)public,private,protected关键字
    RTSP协议
    使用虚函数,减少累赘的if/else/switch
    C++笔记(4)成员函数定义在类内与类外
  • 原文地址:https://www.cnblogs.com/liubaicai/p/3671435.html
Copyright © 2011-2022 走看看