Exchange Web Service 获取邮件的附件并保存到本地的示例代码
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 获取邮件的附件并保存到本地的示例代码的更多相关文章
- 使用 EWS(Exchange Web Service)协议读取邮件、发送邮件
问题: 公司之前可以通过POP3协议收发邮件,因而在SoapUI中用JavaMail可以读取邮件,后来配置了Office 365,POP3协议端口不再开放,邮件全部读取失败,报login timeou ...
- php获取网页中图片并保存到本地
php获取网页中图片并保存到本地的代码,将网页中图片保存本地文件夹: save_img("http://www.jbxue.com" ?>
- php获取网页中图片并保存到本地的代码
php获取网页中图片并保存到本地的代码,将网页中图片保存本地文件夹: <?php /** * 获取网页中图片,并保存至本地 * by www.jbxue.com */ header(" ...
- Fork 多进程 模拟并行访问web service获取响应时间差
#include <ros/ros.h> #include <iostream> #include <string> #include <cstring> ...
- 通过Places API Web Service获取兴趣点数据
实验将爬取新加坡地区的银行POI数据 数据库采用mongodb,请自行安装,同时申请google的key 直接上代码 #coding=utf-8 import urllib import json i ...
- Android 获取截图 并将其保存到本地sd在卡路径
/** * 获取当前屏幕和保存截图 */ private void GetandSaveCurrentImage() { //1.构建Bitmap WindowManager windowManage ...
- 如何获取网页验证码图片并保存到本地(Java实现) [问题点数:40分,结帖人lanxuezaipiao]
http://bbs.csdn.net/topics/390426978 public static String readCheckImage(HashMap<String, String&g ...
- wpf 获取Image的图片并保存到本地
XMAL代码如下: <Image Name="ImageToSave" Source="Images/pic_bg.png" Grid.RowSpan=& ...
- 浅谈Exchange 2013开发-如何操作邮件的附件
因为项目中客户有一个的要求,所以这个Exchange前段时间搞的我很是头疼,没接触过这个东西,但是现在看来,纸老虎一个.希望我的经验可以帮助初次接触它的人少走一些弯路! 简单介绍一下:客户要求在自己的 ...
随机推荐
- [Linked List]Remove Linked List Elements
Total Accepted: 43183 Total Submissions: 160460 Difficulty: Easy Remove all elements from a linked l ...
- Vijos 1121 马拦过河卒
首先要看清题目,卒只能向右或者向下走.而不是四周转.这样的话就无解了. 定义f[i][j],表示走到(i,j)这个点时的总步数.这样就写出了一个递推公式f[i][j]=f[i-1]+f[i][j-1] ...
- jquery 获取select选中的值
获取选中的名称:$("#selectPinType option:selected").text(); 获取选中的值:$("#selectPinType option:s ...
- bootstrap 3 のcheckbox-inline
<div class="form-group"> <p class="control-label"><b> ...
- php-mysql 问题笔记一——在命令行中可以执行的sql语句,无法从php页面页面执行!
我的情况: 1.由于外键较多,插入数据时,提前关闭外键(SET FOREIGN_KEY_CHECKS=0). 2.所使用的sql语句中,有外键绑定到其他表中,所以无法从php页面插入. 原因分析: S ...
- Oracle EBS-SQL (INV-5):检查期间拉式物料领用记录数.sql
select FU.description 操作者, KK.DESCRIPTION ...
- EditPlus3.3 集成 SVN
今天在玩EditPlus的时候,由于自己想上传文件至SVN,本机已经安装了TSVN,听说近期EditPlus支持了SVN操作,于是自己便带着好奇的心试试了. 已有的环境: EditPlus 3 ...
- C#的DLL注册为COM,Delphi来调用
非常实用的东西!过去知道这个方法的话可以解决多少问题啊 首先建立一个C#的DLL工程,写一个类 //Test.csnamespace Test...{public class MyTest...{pu ...
- MySQL RR隔离 读一致性
MySQL RR 模式下 事务隔离问题: Session 1: mysql> select * from test; +------+------+ | id | name | +------+ ...
- Twitter 新一代流处理利器——Heron 论文笔记之Heron架构
Twitter 新一代流处理利器--Heron 论文笔记之Heron架构 标签(空格分隔): Streaming-process realtime-process Heron Architecture ...