使用简单的MAPI(MAPI32)读取.msg/.eml附件 [英] Reading .msg/.eml attachment using simple MAPI(MAPI32)

查看:119
本文介绍了使用简单的MAPI(MAPI32)读取.msg/.eml附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在将电子邮件附件读取为.msg或.eml扩展名时遇到问题,它无法保存在磁盘上,或者在调试模式下在附件[]中显示时也显示null.您能帮助/解决问题还是建议替代方案?

Hi,

I''m facing problem while reading email attachment as .msg or .eml extension, it does not save on disk or also show null while seeing in attachment[] in debug mode. can you please help/resolve the issue or advise alternate.

    private void GetAttachNames( out MailAttach[] aat )
{
aat = new MailAttach[ lastMsg.fileCount ];
Type fdtype = typeof(MapiFileDesc);
int fdsize = Marshal.SizeOf( fdtype );
MapiFileDesc fdtmp = new MapiFileDesc();
int runptr = (int) lastMsg.files;
for( int i = 0; i < lastMsg.fileCount; i++ )
    {
    Marshal.PtrToStructure( (IntPtr) runptr, fdtmp );
    runptr += fdsize;
    aat[i] = new MailAttach();
    if( fdtmp.flags == 0 )
        {
        aat[i].position = fdtmp.position;
        aat[i].name     = fdtmp.name;
        aat[i].path     = fdtmp.path;
        }
    }
}


[edit]从OP注释中添加的代码-OriginalGriff [/edit]


[edit]Code added from OP comment - OriginalGriff[/edit]

推荐答案

对不起,但是该代码没有任何意义.
"fdtmp"永远不会指向任何有用的地方-只是指向一个新的MapiFileDesc对象,然后再放在那里.
我在这里看不到任何经过附件列表的代码.

看看Marshal.PtrToStructure方法:我不认为它可以满足您的期望: MSDN [^ ]

最好的办法是在第一行"aat = new ..."上放置一个断点,然后单步执行,因为我认为您根本没有访问任何有用的东西!
Sorry, but that code doesn''t make a whole lot of sense.
"fdtmp" is never pointed at anywhere useful - just at a new MapiFileDesc object, then left there.
I see no code here that actually goes through a list of attachments.

Have a look at the Marshal.PtrToStructure method: I don;t think it does what you expect: MSDN[^]

The best thing you can do is to put a breakpoint on the first line "aat = new ..." and single step through, because I don''t think you are accessing anything useful at all!


这篇关于使用简单的MAPI(MAPI32)读取.msg/.eml附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆