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前段时间搞的我很是头疼,没接触过这个东西,但是现在看来,纸老虎一个.希望我的经验可以帮助初次接触它的人少走一些弯路! 简单介绍一下:客户要求在自己的 ...
随机推荐
- C# C++ Java接口类型转换
最近这几天做了一个兼职 ,主要是把C语言以及C#语言封装的dll,经过C++中转为Java语言支持的,主要其中的问题就是类型转换,在此列出常用类型的转换过程. #include "stdaf ...
- distance.c
#include "stdio.h" #include "string.h" #include "math.h" #include &quo ...
- 客户端数据持久化解决方案: localStorage
客户端数据持久化解决方案: localStorage localStorage主要用来替代cookie,解决cookie读写困难.容量有限的问题. localStorage有以下几个特点 localS ...
- mongodb与mysql相比的优缺点
与关系型数据库相比,MongoDB的优点:①弱一致性(最终一致),更能保证用户的访问速度:举例来说,在传统的关系型数据库中,一个COUNT类型的操作会锁定数据集,这样可以保证得到“当前”情况下的精确值 ...
- RHEL Channel Bonding
1. 添加 kernel 模块 RHEL5上编辑 /etc/modprobe.conf 加入 alias bond0 bonding options bond0 miimon=100 mode=1 ...
- hdu 5583 Kingdom of Black and White(模拟,技巧)
Problem Description In the Kingdom of Black and White (KBW), there are two kinds of frogs: black fro ...
- Colorbox cannot load the image added by js
As we know, Colorbox is a wonderful js plugin. I came up against a head-banged problem in v1.5.6. Wh ...
- php获取服务器地址
if ( isset( $_SERVER['HTTP_X_FORWARDED_HOST'] ) ) { // Support ProxyPass $t_hosts = explode( ...
- 矩形嵌套(LIS)
矩形嵌套 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 有n个矩形,每个矩形可以用a,b来描述,表示长和宽.矩形X(a,b)可以嵌套在矩形Y(c,d)中当且仅当a& ...
- 【Stackoverflow好问题】Java += 操作符实质
问题 直到今天,我都一直以为: i += j 等同于 i = i + j; 但如果有: int i = 5; long j = 8; 这时 i = i + j不能编译.但i += j却能够编译.这说明 ...