WP8.1StoreApp(WP8.1RT)---发送邮件和短信
2024-08-29 12:25:44
在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
最新文章
- Processing 电子罗盘校准(以 MPU9250为例)
- 提高生产性工具(四) - XML数据库的尝试
- 三进制状压 HDOJ 3001 Travelling
- 邮件格式(HTML/TXT),TXT为文本邮件
- C# 对List<;T>;取交集、连集及差集
- Django实际站点项目开发经验谈
- 改变服务器sshd 的22的端口
- C#打开一个文本文件并读写
- 把NodeJS注册成Windows服务
- 使用GitHub进行协同项目开发和开源项目贡献
- Windows Python 2.7 安装 Numpy
- deep learning 学习资料
- (转)PHP中extract()函数的妙用
- Linux设备驱动中断机制
- Spring Boot Logback应用日志
- C++STL之set容器及stream类
- iOS上传AppStore被拒原因及处理方案
- MySQL学习分享-->;查询-->;查询的分类
- CoreAnimation 视觉效果
- Spring-quartz 可传参(包括service注入)任务调度 多个任务调度
热门文章
- Django中的Model、Form和ModelForm
- django-连接mysql失败
- Windows10 IME占用过高临时解决办法
- 0 1 1 2 3 5 8 13 21 34 求第N个, 用js实现
- MyBatis 注解式开发
- css常用属性总结:文本属性中的text-indent
- python:dist-packages &;&; site-packages
- 11. Container With Most Water 装水最多的容器
- __slots__(面向对象进阶)
- C语言压缩/解压缩