程序园

弹奏键盘人生,拂去青春的尘土,留下的只有岁月的痕迹
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MIME_Entity[] attachments = mime.Attachments;
foreach (MIME_Entity entity in attachments)
{
string fileName = entity.ContentType.Param_Name;
string dir = Server.MapPath("~/d");
string path = Path.Combine(dir, fileName);
if (entity.Body is MIME_b_SinglepartBase)
{
MIME_b_SinglepartBase byteObj = (MIME_b_SinglepartBase)entity.Body;
Stream decodedDataStream = byteObj.GetDataStream();
using (FileStream fs = new FileStream(path, FileMode.Create))
{
LumiSoft.Net.Net_Utils.StreamCopy(decodedDataStream, fs, 4000);
}
}
if (entity.Body is MIME_b_MessageRfc822)
{
MIME_b_MessageRfc822 byteObj = (MIME_b_MessageRfc822)entity.Body;
Mail_Message mm = byteObj.Message;
mm.ToFile(path, null, null);
}
}