Getting Attachments from SafeMailItem returns 1st item twice

C

Chris Miller

Hi,

Im using redemption to get a mail item from outlook, this is working fine,
however, when listing its attachments I run the following code (safeMail is a
valid safemailitem from redemption:

Redemption.Attachments att = safeMail.Attachments;
Redemption.Attachment attachment = null;

for ( int i = 0; i < att.Count; i++ )
{
attachment = att.Item( i );
// regular attachment
if ( attachment.EmbeddedMsg == null )
{
CMessageAttachment baseAtt = new CMessageAttachment(
attachment.FileName, attachment.AsArray as Byte[] );
msg.Attachments.Add( baseAtt );
}

Marshal.ReleaseComObject( attachment );
attachment = null;
}

If i have an email with one attachment it works,
If i have an email with two attachments, it returns the first attachment
twice,
If i have an email with more than two attachments, it returns the first
attachment twice, and the rest of the attachments correctly there after


I'm using c# and interops, although I would have thought this code to be
correct.

Any ideas?


Many thanks
 
C

Chris Miller

OK, sorry guys, my for loop should have been from 1, not 0

Hope this will help somebody else that can't see the wood for the trees...
 
K

Ken Slovak - [MVP - Outlook]

For future reference all Outlook collections start at 1, unlike pure managed
code collections.




Chris Miller said:
OK, sorry guys, my for loop should have been from 1, not 0

Hope this will help somebody else that can't see the wood for the trees...

Chris Miller said:
Hi,

Im using redemption to get a mail item from outlook, this is working
fine,
however, when listing its attachments I run the following code (safeMail
is a
valid safemailitem from redemption:

Redemption.Attachments att = safeMail.Attachments;
Redemption.Attachment attachment = null;

for ( int i = 0; i < att.Count; i++ )
{
attachment = att.Item( i );
// regular attachment
if ( attachment.EmbeddedMsg == null )
{
CMessageAttachment baseAtt = new CMessageAttachment(
attachment.FileName, attachment.AsArray as Byte[] );
msg.Attachments.Add( baseAtt );
}

Marshal.ReleaseComObject( attachment );
attachment = null;
}

If i have an email with one attachment it works,
If i have an email with two attachments, it returns the first attachment
twice,
If i have an email with more than two attachments, it returns the first
attachment twice, and the rest of the attachments correctly there after


I'm using c# and interops, although I would have thought this code to be
correct.

Any ideas?


Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top