Getting Attachments from SafeMailItem returns 1st item twice

  • Thread starter Thread starter Chris Miller
  • Start date Start date
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
 
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...
 
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
 
Back
Top