Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]Code added from OP comment - OriginalGriff[/edit]
Posted
Updated 15-Mar-11 23:08pm
v3
Comments
OriginalGriff 16-Mar-11 3:34am    
Without seeing the code you are using, it is impossible to tell what is happening.
Please edit you question, and provide relevant code fragments.
nilesh_lohani 16-Mar-11 3:42am    
Below code here
---------------
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;
}
}
}

when attachment is .msg or .eml then fdtmp.name contains null.

1 solution

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!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900