getting attachments

J

Jonatan

Hi there,

I am stuck in a problem and I don't seem to find the answer in the
groups.

I am developing an addin in c# in outlook 2003.

When the user forwards one PostItem, outlook creates a MailItem and
puts the documents contained in the PostItem as attachment of the
MailItem.

When the user forwards two or more Post Items together, outlook creates
a MailItem and puts the PostItems as attachments. Each of them with its
attachments.

I am capturing the item send event. I want to remove the PostItems from
the attachments of the MailItem and just leave the attachments that the
PostItems contain.

That has been impossible to accomplish!

When I get the attachmets of the MailItem I get a ".msg". It is not
possible to get its attachments using the Outlook object model.

I read in the groups that you can access to the attachments using
Redemption because it has the EmbeddedMsg property. I tried it but to
no avail.

The first problem with Redemption is that when I set the Item property
of the SafeMailItem, the attachments collection continues being null.
Then I decided to save the attachments in the hard disk and then add an
Redemption Attachment. No joy. The property EmbeddedMsg is null.

I am posting the code, I may be doing something wrong!


Outlook.MailItem mailItem ... // This is the MailItem that I receive
from the ItemSend event

Redemption.SafeMailItem safeMailItem = new
Redemption.SafeMailItemClass();

safeMailItem.Item = mailItem;

// I can't use safeMailItem Attachments.Count because is 0
if (mailItem.Attachments.Count > 1)
{
for (int i = mailItem.Attachments.Count; i > 0; i--)
{
Outlook.Attachment attachment = mailItem.Attachments;

attachment.SaveAsFile(@"c:\" + fileName.ToUpper());

safeMailItem.Attachments.Add(@"c:\" + fileName.ToUpper(),
Outlook.OlAttachmentType.olByValue, 1, fileName);

Redemption.Attachment safeAttachment = safeMailItem.Attachments[1];

// This line crashes because the EmbeddedMsg is null (not
defined)
Redemption.MessageItem messageItem =
safeAttachment.EmbeddedMsg;
}
 
S

Sue Mosher [MVP-Outlook]

As always, with Redemption when you are working with an unsent mesage, you must save it first
before passing it to the Redemption.SafeMailItem. That may explain why you're not able to get to EmbeddedMsg.

Alternatively, save the .msg files. Since all you want is their attachments, you can make a copy of each with the Application.CreateItemFromTemplate method.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

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