.net 读取exchange邮件

5月份的时候公司要求开发一个程序,现在才想起记下来

需求:公司要求商城客服将订单文件发送至指定邮箱,由程序自动下载邮箱里的附件至指定目录

解决方案:开发.net程序,每隔一个时间段读取邮箱内容,如为订单邮件,则下载附件

技术要点:exchange webservice

 

调用引用exchange 的webservice程序,exchange webservice的引用 url 格式一般为 https://{yourmailserver}/EWS/Services.wsdl

exchange webservice提供了丰富的类库,具体可查看MSDN具体自己看代码吧,不想多说了,发觉程序员都喜欢用代码说话,我也不例外

另外开发这个程序借鉴了 http://blog.csdn.net/oyjd614/article/details/2754104

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnionMallSync.tiger8;
using System.Net;
using System.Text.RegularExpressions;
using AppLibrary.Read.Biff;
using System.IO;
using System.Windows.Forms;

namespace UnionMallSync.YaoDian
{
    public class YaoDianMail
    {
        private string user = YaoDianSetting.mailUserName;
        private string pwd = YaoDianSetting.mailPassWord;
        private string domain = YaoDianSetting.mailDomain;
        private string url = YaoDianSetting.mailUrl;
        private Regex mailNamer = new Regex("威易(\\d+[\\.-]){1,2}\\d+\\.\\w+");
        private string path = @"D:\新建文件夹";
        private string sevenZip = @"C:\Program Files\7-zip\7z.exe";


        /// <summary>
        /// 自动将耀点发来的订单附件保存至yaodianOrder目录
        /// </summary>
        public void AutoSaveOrder()
        {
            //建立exchage连接
            ExchangeServiceBinding esb = ExchangeServer(user, pwd, domain, url);
            //获取邮件附件
            List<FileAttachmentType> attachmentList = GetMailAttachFile(esb);
            foreach (FileAttachmentType attachment in attachmentList)
            {
                if (mailNamer.IsMatch(attachment.Name))
                {
                    string folder = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                    if (!Directory.Exists(path + "\\" + folder))
                    {
                        Directory.CreateDirectory(path + "\\" + folder);
                    }
                    FileStream fs = System.IO.File.Create(path 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值