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);
}
}
}
}
} }

Exchange Web Service 获取邮件的附件并保存到本地的示例代码的更多相关文章

  1. 使用 EWS(Exchange Web Service)协议读取邮件、发送邮件

    问题: 公司之前可以通过POP3协议收发邮件,因而在SoapUI中用JavaMail可以读取邮件,后来配置了Office 365,POP3协议端口不再开放,邮件全部读取失败,报login timeou ...

  2. php获取网页中图片并保存到本地

    php获取网页中图片并保存到本地的代码,将网页中图片保存本地文件夹: save_img("http://www.jbxue.com" ?>

  3. php获取网页中图片并保存到本地的代码

    php获取网页中图片并保存到本地的代码,将网页中图片保存本地文件夹: <?php /** * 获取网页中图片,并保存至本地 * by www.jbxue.com */ header(" ...

  4. Fork 多进程 模拟并行访问web service获取响应时间差

    #include <ros/ros.h> #include <iostream> #include <string> #include <cstring> ...

  5. 通过Places API Web Service获取兴趣点数据

    实验将爬取新加坡地区的银行POI数据 数据库采用mongodb,请自行安装,同时申请google的key 直接上代码 #coding=utf-8 import urllib import json i ...

  6. Android 获取截图 并将其保存到本地sd在卡路径

    /** * 获取当前屏幕和保存截图 */ private void GetandSaveCurrentImage() { //1.构建Bitmap WindowManager windowManage ...

  7. 如何获取网页验证码图片并保存到本地(Java实现) [问题点数:40分,结帖人lanxuezaipiao]

    http://bbs.csdn.net/topics/390426978 public static String readCheckImage(HashMap<String, String&g ...

  8. wpf 获取Image的图片并保存到本地

    XMAL代码如下: <Image Name="ImageToSave" Source="Images/pic_bg.png" Grid.RowSpan=& ...

  9. 浅谈Exchange 2013开发-如何操作邮件的附件

    因为项目中客户有一个的要求,所以这个Exchange前段时间搞的我很是头疼,没接触过这个东西,但是现在看来,纸老虎一个.希望我的经验可以帮助初次接触它的人少走一些弯路! 简单介绍一下:客户要求在自己的 ...

随机推荐

  1. Linux下Matlab崩溃的解决方法

    猜想主要是因为图形显示用了OpenGL加速造成不稳定. 我的运行环境是: Ubuntu 10.04 LTS 64bit Matlab R2010b 解决方法是启动时用: $MATLAB_DIR/bin ...

  2. python学习笔记:python对象

    一.python对象 python使用对象模型来存储数据,构造任何类型的值都是一个对象.所有的python对象都拥有三个特性:身份.类型和值. 身份:每个对象都有一个唯一的身份标识自己,对象的身份可以 ...

  3. ArrayList--卧槽这就是源码

    最近在<数据结构与算法分析(java版)>中看到了实现ArrayList的简易代码,亲自做了一下.个中的疑点还是在代码中实现了一下.其中就包括内部类Iterator对外部成员访问的问题. ...

  4. arrowTip 提示

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  5. Visual Studio 2012 Update3 安装失败错误“正在关闭管道'

    问题描述: Visual Studio 2012 update3 安装失败错误“ 正在关闭管道' 环境: Windows 7 SP1(x86和x64) Windows 8(x86和x64) Windo ...

  6. netbean7.4 保存远程项目的时候老是跳警告框的解决方案

    在任意位置新建一个空白文件,然后在 管理远程连接里面=>已知的主机文件=>点浏览就行了

  7. 动态规划——数字三角形(递归or递推or记忆化搜索)

    动态规划的核心就是状态和状态转移方程. 对于该题,需要用抽象的方法思考,把当前的位置(i,j)看成一个状态,然后定义状态的指标函数d(i,j)为从格子出发时能得到的最大和(包括格子本身的值). 在这个 ...

  8. 二叉查找树的Insert和Delete操作

    struct TreeNode{ SearchTree Left; SearchTree Right; ElementType Ele; }; /*递归一定有出口*/ /*递归代码就是要重复使用*/ ...

  9. 【POJ】1330 Nearest Common Ancestors ——最近公共祖先(LCA)

    Nearest Common Ancestors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18136   Accept ...

  10. Android UI SurfaceView的使用-绘制单个图型或多个图形

    新建MyView类继承自SurfaceView: public class MyView extends SurfaceView implements SurfaceHolder.Callback { ...