读书人

怎么用CDO得到eml邮件的信息和附件内容

发布时间: 2013-08-09 15:16:24 作者: rapoo

如何用CDO得到eml邮件的信息和附件内容
google了很多.在CSDN找到个比较考谱的帖, 但是弄到C#下面时候有问题. 尤其是不能解析elm中base64的附件

现在问题就是如果可以把base64的stream提取出来, 然后可以让我用decoder base64的方法转换成文件,

谢谢大家, 如果你有更好的解决方法, 不妨说说. 谢谢.

某兄弟的原帖: http://topic.csdn.net/t/20060116/05/4518423.html

我的code:

protected void Page_Load(object sender, EventArgs e)
{
CDO.Message oMsg = new CDO.Message();

string emlFilePath = @"c:\test.eml";
ADODB.Stream stm = new ADODB.Stream();
stm.Open(System.Reflection.Missing.Value,
ADODB.ConnectModeEnum.adModeUnknown,
ADODB.StreamOpenOptionsEnum.adOpenStreamUnspecified,
"", "");
stm.Type = ADODB.StreamTypeEnum.adTypeBinary;

stm.LoadFromFile(emlFilePath);

oMsg.DataSource.OpenObject(stm, "_stream");

stm.Close();
CDO.IBodyPart iPrt;
int attachemtnCount = oMsg.Attachments.Count;

for (int i = 1; i <= attachemtnCount; i++) {

byte[] info_AttachmentBody;
ADODB.Stream stm1;

iPrt = oMsg.Attachments[i] ;
string attachmentFileName = iPrt.FileName;


Label1.Text += attachmentFileName; //Get the eml attachment List
if (iPrt.ContentTransferEncoding == "7bit ")
{
//string_encoding = iPrt.GetDecodedContentStream.ReadText(iPrt.GetDecodedContentStream.Size)
System.Text.ASCIIEncoding oEncoder = new System.Text.ASCIIEncoding();
info_AttachmentBody = oEncoder.GetBytes(iPrt.GetDecodedContentStream().ReadText(iPrt.GetDecodedContentStream().Size));

}
else //如果是base64的话..这里不会了.
{
stm1 = iPrt.GetDecodedContentStream();
stm1.Read(iPrt.GetDecodedContentStream().Size);
Label1.Text += stm1.ToString();
}

}

}


}


[解决办法]
如此的好东西居然给埋没了!谢谢楼主分享

读书人网 >asp.net

热点推荐