Outlook vsto - properties handling - c#

i have a problem with MailItem properties in a Outlook VSTO. I add some custom properties to a previously exported .msg mail with e.g. redemption in the following way:
SafeMailItem smi = new SafeMailItem {
Item = mailItem
};
int propertyId = smi.GetIDsFromNames(PROPERTY_GUID, "anyID");
smi.Fields[propertyId] = propertyString;
This property is removed and i cant find it again if i click on sending the mail. I checked this with Outlook Spy and before i send the mail the property is available but after i click on send (and e.g. cancel the send) the property is gone.
I also tried to call MailItem.Save() (at any time) but it has no effect apart from the fact that the .msg file includes the mail edits :). The same behavior is given if i use MailItem.PropertyAccessor directly.
Can anybody explain me why the properties are removed and how to fix this issue?
Thanks a lot for support
Outlook version: 16.0.0.13530 (64-bit); Visual Studio Professional 2019 16.8.4

Related

Outlook VSTO Add-In C# Events - Events not triggered anymore after some time

currently I'm developing a small VSTO Outlook Add-In. While I've some experience in C#, I'm not very familiar with the Outlook object model.
The scope of my Add-In is pretty easy. My colleagues and I have a shared Outlook inbox (beside our own ones). The shared inbox has categories and subfolders with the same name. E.g. there’s a subfolder “Michael” and there exists a category “Michael”. When somebody applies his own category to a mail in the shared inbox, the mail is automatically moved to the matching subfolder, the reply window opens and the sender address is changed from the shared email address to the personal one (our IT adjusted the shared mail address to not be able to send emails).
Right now the current version of the Add-In works flawlessly, beside the fact that it somehow stops to work after some time. So when I start outlook, everything works like expected, I can categorize mails in the shared inbox and they’re moved etc. But after some time (sometimes hours, sometimes even after 30 minutes) it’s not working anymore. Neither the debug view in Visual Studio nor Outlook are indicating any errors. At first I thought something terminated my Add-In, but then I configured a timer to send a “I’m alive” message to the log file and now I can see that the Add-In is still running.
Hence I assume that somehow the events I’ve registered to are not sufficient to keep track of the users action in Outlook. This can be confirmed as a break point in the event handlers is not triggered when this behavior appears and a mail is categorized. I’ve registered to the following events in the startup method:
Outlook.Application application = this.Application;
Outlook.Inspectors inspectors = application.Inspectors;
Outlook.Explorer activeExplorer = this.Application.ActiveExplorer();
// When a new mail is created, trigger Inspectors_AddTextToNewMail() methode
inspectors.NewInspector = new Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_AddTextToNewMail);
// Whenever something in the explorer is selected, run the event handler
activeExplorer.SelectionChange += ActiveExplorer_SelectionChange;
In the selectionChange() Event-Handler another Event-listener for the change of the mail properties is registered:
Outlook.MailItem mailItem = selectedItem as Outlook.MailItem;
// Register an Event handler that listens for changes of the mailitem's properties in order to check the category
mailItem.PropertyChange += MailItem_PropertyChange;
This way I can check whether a category has been applied.
But after some time not even the ActiveExplorer_SelectionChange Event is triggered, independent on what I select in Outlook.
Does anybody know whether I missed something? Do I have to register to further events so the Add-In won’t lose track?
Thanks for your help in advance!
Best Regards,
Percy
You need to declare the variables application, inspectors and activeExplorer on the global (class) level to prevent them from being released by the Garbage Collector.

Outlook is randomly deleting attachment(s) from mailitem during item send event

I'm currently experiencing some strange behavior when sending e-mails using Outlook (Office 365 Pro Plus).
Our software can generate e-mails and show a new mail compose to the user with attachments which they selected from our software. (We use both Redemption from our software as Outlook Object Model using an Outlook Add-in Express add-in)
Below you can find the code for generating the e-mail using Redemption:
bool createEmail = false;
RDOSession session = new RDOSession();
session.Logon("", "", false, false, null, false);
RDOFolder folder = session.GetDefaultFolder(rdoDefaultFolders.olFolderDrafts);
RDOMail mail = folder.Items.Add("IPM.Note");
... Code for selecting receivers (returns string with emailadresses) ...
... Code for converting word documents to PDF / Adding the attachments to the mailitem ...
RDOUserProperty userProp = mail.UserProperties.Add("DMS_AttachmentCount", rdoUserPropertyType.olInteger, false, false);
userProp.Value = mail.Attachments.Count;
mail.Display();
I noticed that I'm not using
mail.Save();
Could that be the issue?
When we show the user the generated e-mail all attachments are in place and the user is able to open the attachments.
So far so good...
Here comes the problem:
On sending the e-mail, sometimes (i mean really sometimes) some of the
attachments are deleted from the e-mail. When the user goes to it's
sent items and selects the e-mail, some of the attachments are
deleted.
Since this occurs randomly, I'm not able to debug this issue.
What have I tried already:
Turn off ESET Nod32 and all of it's e-mail components
Disabled Office Secured Mode
Exclude certain file extensions from being scanned.
Checked for third party add-ins, so far only the list below is installed
The rest of the add-ins are default by Outlook
My question(s):
Is there somebody out there that has experienced the same problem?
How can I determine what happens inside the Item Send event?
What else can I turn off or apply on the server that might prevent this issue from happening?
Thanks.

Setting Outlook signature for multiple accounts

I am in the process of writing an application that sets a signature based on pre-acquired data for each Microsoft Outlook account(a user may have multiple Outlook accounts for various purposes).
I am able to set a signature for the default account, but I have yet to find how to set a signature for each Outlook account individually. I have done a lot of my own research and poked around the Microsoft.Office.Interop objects without much luck.
Is there a way to achieve this?
To choose the Outlook profile programmatically, you just use
Microsoft.Office.Interop.Outlook.Application App =
new Microsoft.Office.Interop.Outlook.Application();
NameSpace mapi = App.GetNamespace("MAPI");
mapi.Logon(profileName);
obviously setting the profileName to what is shown in the dropdown list upon starting Outlook (if you do not set a default profile in the control panel email settings).
This however is problematic in a number of ways since Outlook does not support multiple sessions even though the MAPI logon does:
http://msdn.microsoft.com/en-us/library/bb219914(v=office.12).aspx
Meaning: if Outlook is already running, you can even set NewSession to true, but it won't help. It will give you the currently-logged-in profile regardless of what name you set. If you have an Outlook zombie (I got that while testing, check with task manager), i.e. an Outlook without an UI showing up, the problem is the same.
If you can ensure Outlook does not run while doing stuff with signatures, you should be fine though.

Wanting to email from C# with attachment like MS Word

This is really odd that I can't seem to find out how to do this, so I'm wondering if I'm missing something obvious.
I'm wanting to put a menu on our application like is found in Word and Excel, File -> Send To -> Mail Recipient (As Attachment)
Our requirements are to create and display the email with the attachment, just like Word and Excel do, not to send it automatically.
We used to be able to save the file to the temp folder and use:
Shell.Execute("mailto:my.email.com?subject=File&attachment="c:\temp.txt");
I've tried the &attach, &attachment in both VB.NET and C# with quotes, double quotes, etc. I've also tried System.Net.Mail but don't see anywhere that you can display the email, it only seems to be able to create and send.
We can't assume a default email client, it could be Outlook Express, Outlook version 2000, 2003, or 2007, or lotus notes, or ... Don't know. We have a commercial application so I don't think we can assume a specific application. Like MS Word, it needs to work for whatever is installed (or isn't installed).
I've done this using Outlook interop from Visual Studio Tools for Office:
using IntOut = Microsoft.Office.Interop.Outlook;
...
IntOut.Application app = new IntOut.Application();
IntOut.MailItem item = (IntOut.MailItem)app.CreateItem(
IntOut.OlItemType.olMailItem);
item.Subject = "Hello world";
item.Body = "Hello!";
item.Display(false); // set to true to make mail window modal
You can find some samples on MSDN here.
For the general case, there isn't a way to do this. Here's Microsoft's documentation: http://msdn.microsoft.com/en-us/library/aa767737(VS.85).aspx
If you can provide the mail client, you may get a better answer.

C# opening up a blank email with an attachment using Exchange

I'm new to the world of C# programming but was hoping someone could help me out.
I'm trying to use C# to open up a blank email in Outlook with a specified attachment.
In other words, open the email, the TO: and SUBJECT: fields are blank but the email has an attachment that is specified in my code. I want my user to be able to modify the email and send to whatever users s/he specifies. I know for sure that we have Exchange....so any ideas?
There are a number of way you can do this.
Create an Outlook addin that opens a new mail with the attachment you want via say a new toolbar button.
Do the same in Outlook VBA macro ..
Also you could create a new form with the attachment in it already and then just us that form.(but the attachment will be hard coded etc.)
Does the attachment change ? or is it the same one evey time ? what outlook version are you using ? What are you programing capabilties ?
76mel
I don't think exchange will help you much, you need to work with outlook on the users machine. You can add a reference to the Outlook interop assemblies, should be in the Com tab of your add references dialog.
Here's some links to jump start you.
http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.aspx
http://www.microeye.com/resources/res_tech_vsnet.htm
Good Luck!

Categories

Resources