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