private static void DownLoadMailAttachments(ExchangeService service, ItemId itemId)
{
EmailMessage message = EmailMessage.Bind(service, itemId, new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.Attachments)); ; if (message.HasAttachments)
{
foreach (MailAttachment attachment in message.Attachments)
{
FileAttachment fileAttachment = attachment as FileAttachment; ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null)
{
itemAttachment.Load(EmailMessageSchema.MimeContent); char[] invalidChars = Path.GetInvalidPathChars();
string name = itemAttachment.Name; foreach (char invalidChar in invalidChars)
{
name = name.Replace(invalidChar, ' ');
} name = name.Replace(":", " "); string emailPath = Path.Combine(Path.GetTempPath(), name + ".eml"); using (FileStream stream = File.Open(emailPath, FileMode.Create, FileAccess.ReadWrite))
{
foreach (byte content in itemAttachment.Item.MimeContent.Content)
{
stream.WriteByte(content);
}
} } if (fileAttachment != null)
{
string filePath = Path.Combine(Path.GetTempPath(), fileAttachment.Name); fileAttachment.Load(); using (FileStream stream = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite))
{
foreach (byte content in fileAttachment.Content)
{
stream.WriteByte(content);
}
}
}
}
} }

最新文章

  1. spring静态代理
  2. [nRF51822] 7、基础实验代码解析大全(前十)
  3. android NDK debug 遇到的问题与解决方法
  4. Ueditor 编译发布后无法使用上传图片、附件等功能
  5. 关于OpenVPN的入门使用
  6. js/jquery 实时监听输入框值变化的完美方案:oninput & onpropertychange
  7. 【python】list。列表
  8. Scala第四章学习笔记(面向对象编程)
  9. java socket 单服务器多客户端实时通信
  10. 给产品经理讲技术,不得不懂的TCP和UDP
  11. HDU_1071——积分求面积,抛物线顶点公式
  12. (转)[老老实实学WCF] 第四篇 初探通信--ChannelFactory
  13. 存储、读取——Android应用程序内置的文件夹
  14. MySql单表最大8000W+ 之数据库遇瓶颈记
  15. Ubuntu16.04+CUDA8.0+CUNN5.1+caffe+tensorflow+Theano
  16. ThinkPHP的Rbac权限控制
  17. idea为tomcat设置虚拟地址
  18. 手动(原生ajax)和自动发送ajax请求 伪ajax(Ifrname)
  19. CF912E Prime Gift
  20. C语言基础:分支语句和常见运算符 分类: iOS学习 c语言基础 2015-06-10 21:44 13人阅读 评论(0) 收藏

热门文章

  1. PARTITION(number theory) ALSO Explosive number in codewars
  2. sql的集合运算
  3. php中的一些编程例子
  4. 关于css3的边框的border-radius和border-image用法的详解
  5. Android05-UI02布局,自定义控件,ListView
  6. php 汉字转换成拼音
  7. Delphi 取外网IP
  8. ping-tool
  9. 迎接 Windows Azure 和 DNN 挑战,几分钟内快速构建网站!
  10. 打开网页自动弹出QQ临时会话 (打开网站弹出QQ聊天) qq.js文件代