0

I'm trying to create a copy of a mailItem in my sent folder. Once I create it, I save the msg in the folder. It works for all mailItems , except when I try to save a mailItem with an attachment where I disallow the save attachment permission in outlook. Why does the mailItem.Save() not saving the mailItem only for this scenario? In the code below, I'm using redemptions to create a copy in sent folder. msg.save() saves all mails but the one I mentioned above. Also I tried saving the mailItem before the creation, but it does not generate entryId.

static void CreateSentFolderMail(Redemption.SafeMailItem newSentMail, string nvdID, Outlook.MailItem mailItem, Redemption.SafeMailItem safeMailItem)
{       
    RDOFolder folder = Globals.ThisAddIn.session.GetDefaultFolder(rdoDefaultFolders.olFolderSentMail);
    RDOMail msg = (RDOMail)folder.Items.Add(newSentMail);
    RDOMail originalmsg = Globals.ThisAddIn.session.GetMessageFromID(mailItem.EntryID);
    msg.Sent = true;
    msg.SentOn = DateTime.Now;
    msg.ReceivedTime =msg.CreationTime;
    msg.Subject = safeMailItem.Item.Subject;
    msg.To = safeMailItem.Item.To;
    msg.BCC = safeMailItem.Item.BCC;
    msg.Body = safeMailItem.Item.Body;
    msg.Recipients = originalmsg.Recipients;
    msg.Sender = Globals.ThisAddIn.session.CurrentUser;
    msg.SentOnBehalfOf = Globals.ThisAddIn.session.CurrentUser;
    msg.SetProps(NVDMailHeaderUtils.PS_INTERNET_HEADERS + NVDMailHeaderUtils.NVD_HEADER_ID, nvdID);
    msg.Save();
} 
DuDa
  • 3,718
  • 4
  • 16
  • 36
amrutha
  • 11
  • 2
  • Are you getting a particular error? – Dmitry Streblechenko Jan 14 '21 at 16:19
  • Also note that you are (potentially) wiping HTML formatting by setting the plain text Body property. Note that you can copy all properties by calling `originalmsg.CopyTo(msg)`. – Dmitry Streblechenko Jan 14 '21 at 16:21
  • I understood why the save was failing for this scenario in particular, it was due to the bug : Using RDOSession.GetRDOObjectFromOutlookObject or Safe*Item against an unsaved message could prevent that message from ever being saved and could raise an exception (Exceed maximum allowed of hooks) after GetRDOObjectFromOutlookObject was called a few times. – amrutha Jan 18 '21 at 08:11
  • Now i have another issue, its with the entry ID. I always get IMapi invalid entryID error. Is there any other way that i could fetch the RDOrecipients without using entryID? – amrutha Jan 18 '21 at 08:13
  • I am not sure I understand - do you mean you get some entry id, but the code fails when you attempt to use it? What is the relevant snippet of your code? – Dmitry Streblechenko Jan 18 '21 at 18:27

1 Answers1

1

I had used session.GetRDOObjectFromOutlookObject before calling this method to get a RDOAttachment object. But after using this: session.GetRDOObjectFromOutlookObject I was not able to the save the mailitem. Save was not getting executed and hence the EntryId was not getting generated. Due to this issue I was getting an error here : RDOMail originalmsg = Globals.ThisAddIn.session.GetMessageFromID(mailItem.EntryID); saying "invalid entry Id". I installed the new version of redemptions that solved this problem.

amrutha
  • 11
  • 2