Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Add-Ins / October 2005

Tip: Looking for answers? Try searching our database.

getting attachments

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jonatan - 21 Oct 2005 17:02 GMT
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[i];

    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;
  }
Sue Mosher [MVP-Outlook] - 21 Oct 2005 19:18 GMT
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.

Signature

Sue Mosher, Outlook MVP
  Author of Configuring Microsoft Outlook 2003
    http://www.turtleflock.com/olconfig/index.htm
  and Microsoft Outlook Programming - Jumpstart for
    Administrators, Power Users, and Developers
    http://www.outlookcode.com/jumpstart.aspx

> Hi there,
>
[quoted text clipped - 58 lines]
> safeAttachment.EmbeddedMsg;
>   }
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.