Redemption GetRDOObjectFromOutlookObject creates conflicting issues on save - c#

I am currently using GetRDOObjectFromOutlookObject to get the RDOAttachment object from outlook attachment. Although I could successfully use the object for the functionality I needed to achieve. Once the mail item is sent , outlook triggers a save and there I have conflicting issue that causes the outlook repair tool error. I realized that this happens when two copies of the same message is opened, Outlook fails to save the mail and throws the error. How do I overcome this issue?
foreach (Outlook.Attachment at in mail.MailItem.Attachments)
{
Redemption.IRDOAttachment rDOAttachment;
rDOAttachment = Globals.ThisAddIn.session.GetRDOObjectFromOutlookObject(at);
rDOAttachment.DisplayName = at.DisplayName;
Is this a bug in redemption or am I missing something here?

I used the below code by getting RDOAttachments from RDOMail rather than GetRDOObjectFromOutlookObject.
RDOMail msg = Globals.ThisAddIn.session.GetMessageFromID(redemptionMailItem.Item.EntryID);
RDOAttachments redemptionAttachments = msg.Attachments;
This solved the issue, But having said that there is a bug GetRDOObjectFromOutlookObject, that makes it unreliable to use it.

Related

C# Attach to open outlook email, edit and send

I am trying get some C# to attach to an open reply-email (triggered manually by user), on the already running instance of Outlook (opened manually by user). The code should identify the open reply email, edit the subject line and body of the email and send the email.
The problem is that I get as far as identifying the running instance of Outlook and assigning it to an object using one of the Marshal methodsoutApp = Marshal.GetActiveObject("Outlook.Application") as Application, but then I cannot cast it to a MailItem type in order to manipulate its elements e.g. the subject line, body, etc...something like MailItem mailItem = (MailItem)outApp.CreateItem((OlItemType.olMailItem)); throws an invalid cast exception at runtime.
Apologies if I am wrong, but could not find a single example close to this exact sequence of events, one of the closer ones is this post c# outlook open existing instance and reply to email
but then it goes a whole different way. There are tons of posts on how to use the Microsoft.Office.Interop.Outlook to OPEN and then use an instance of Outlook, but hardly anything (that I could find) on how to use an open instance. Any help is appreciated, thank you.
EDIT 08102019:
The code is used from an RPA platform, so there is no risk of it being picked up as malware. The "user" is just a virtual user on an account with purpose-made permissions and a controlled environment...sorry, nothing dark here :-). Anyway, here is the code I am using at the moment which creates a new instance and saves it to drafts in Outlook. It is not what I set out to do, as I explained above, this is just a temporary fix:
OutlookApp outlookApp = new OutlookApp();
MailItem mailItem = (MailItem)outlookApp.CreateItem(OlItemType.olMailItem);
mailItem.To = "test#test.com";
mailItem.Subject = "Test Email Generation";
mailItem.HTMLBody = "<html><body>This is the body of the email.</strong>.<br/> This is another line in the body of the email.</body></html>";
mailItem.Display(false);
System.Threading.Thread.Sleep(3000);
mailItem.Close(OlInspectorClose.olSave);
Marshal.ReleaseComObject(outlookApp);
To get the opened mail item in the inspector window you need:
Use the ActiveInspector method to get an instance of the Inspector class.
The Inspector.CurrentItem property returns an Object representing the current item being displayed in the inspector.
Set any properties like Subject, Body, Recipients and etc.
To get the inline response in the Explorer window you need to use the Explorer.ActiveInlineResponse property which returns an item object representing the active inline response item in the explorer reading pane.

Outlook.MailItem custom properties issue

i have the following situation for my Add-In (Office >= 2010):
I want to add some custom properties to an Outlook.MailItem (property must be mail associated) while the mailtext is written.
If this mail is sent i want to grap the send event and get the previously set properties again, doing something and removing the properties and continue sending.
Problem if i use PropertyAccessor:
I use it as follows to save the property while writing the mail:
string propTag = "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/test_property"
mailItem.PropertyAccessor.SetProperty(propTag, value);
And to read the property again on sending the mail:
string propTag = "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/test_property"
string readProperty = mailItem.PropertyAccessor.GetProperty(propTag);
works if cached mode is enabled on exchange
works NOT if cached mode isn't enabled... i can't find the previously setted properties anymore (Exception with unknown property is thrown)
OutlookSpy (http://www.dimastr.com/outspy/home.htm) can find the property on sending so does anyone knows how to read the properties in a different way?
I would thank you very much for every help.
You need to call Save if you want your changes to be persisted.

Outlook does not recognize one or more names. From 1 computer

I am trying to send an email with several recipients. On most machines, the program works as expected, but on one I get the following error. System.Runtime.InteropServices.COMException (0x80004005): Outlook does not recognize one or more names.
I have narrowed down what address the machine thinks is the issue and there is nothing wrong with it.
I have tried using using both the recipients and To fields as follows:
Outlook.MailItem outLookMsg = outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipients recips = outLookMsg.Recipients;
Outlook.Recipient recip = recips.Add("'doesntWork#test.com'");
recip.Type = OlMailRecipientType.olTo;
outLookMsg.Send()
As well as
Outlook.MailItem outLookMsg = outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
outLookMsg.To = "'doesntWork#test.com'";
outLookMsg.Send()
I have tried forcing the program to use the literal email address without resolving by using 'doesntwork#test.com' with and without the single quotes, but that does not work. I really don't want outlook to try and resolve the recipient, I just want it to send the email. Anyone run into this before?

Read Undelivered email body in C# windows form

I am developing one tool to keep track of emails and would like to trace the emails undelivered to sender.
I dont want to use any third party tool or any external reference
What I have tried?
-To read report Item but Body is in Chinese like language
-Googled on some solutions but nothing is working i.e. solution is related to
//PR_TRANSPORT_MESSAGE_HEADERS
link to get property name "http://schemas.microsoft.com/mapi/proptag/0x0C1A001F"
outlook PropertyAccessor class
PropName link is not working anymore.
Could anyone here please help me I would like to get from which sender the email delivery is failed.
Thank you in advance.
The PR_TRANSPORT_MESSAGE_HEADERS property contains the same Diagnostic information shown in the body. You just need to read it using the PropertyAccessor class and parse the string with From and To entries.
Outlook.PropertyAccessor oPA = reportItem.PropertyAccessor;
string transportHeaders = (string)oPA.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");

Using Redemption RDOContactItem cannot save more than a number of contacts MAPI_E_TOO_BIG

found I'm trying to create contacts into a user's Mailbox programmatically (using Redemption), based on values from a database.
RDOContactItem rci = (RDOContactItem)session.GetDefaultFolder(rdoDefaultFolders.olFolderContacts).Folders["Contacts Subfolder"].Items.Add("IPM.Contact");
...
rci.Save();
As soon as I reach the limit 250, I get the error:
Error in IMsgStore::OpenEntry(Inbox or Root): MAPI_E_TOO_BIG
ulVersion: 0
Error: Your server administrator has limited the number of items you can open simultaneously. Try closing messages you have opened or removing attachments and images from unsent messages you are composing.
Component: Microsoft Exchange Information Store
Read Dmitry Streblechenko's comments on "This is an indication that you have too many open objects. Do you open each and every message in a folder?" suggestions on http://www.microsoft-questions.com/microsoft/Plaform-SDK-Mapi/32731171/mapietoobig.aspx and even tried his suggestion "Do you release all Exchange objects as soon as you are done with them?"
if (rci != null) Marshal.ReleaseComObject(rci);
even casting to IDisposable to able to dispose it, but it didn't work.
I haven't find a way to close a contact item after being saved.
Increasing the number of items that can be opened simultaneously on the server side is not a happy option either.
How to solve this?
You are using multiple dot notation (5 if I am counting correctly), and that causes the compiler to create implicit variables that you cannot explicitly release. Try the following. You can also try to call GC.Collect() every once in a while, but that would be a sledgehammer of a solution...
RDOFolder contacts = session.GetDefaultFolder(rdoDefaultFolders.olFolderContacts);
RDOFolders folders = contacts.Folders;
RDOFolder subfolder = folders["Contacts Subfolder"];
RDOItems items = subfolder.Items;
RDOMail msg = items.Add("IPM.Contact");
RDOContactItem rci = (RDOContactItem)msg;
...
rci.Save();
Marshal.ReleaseComObject(rci);
Marshal.ReleaseComObject(msg);
Marshal.ReleaseComObject(items);
Marshal.ReleaseComObject(subfolder);
Marshal.ReleaseComObject(folders);
Marshal.ReleaseComObject(contacts);

Categories

Resources