I am working on a project, which displays a customicon and an informationarea in Outlook 2010 for special messages. To achive this, I change the MessageClass of the message. This works great, aslong as the message isn't digitally signed.
Here is the code to change the MessageClass:
public static void SetMessageClass(ref Outlook.MailItem mi) {
try {
if (mi.MessageClass.ToLower() == "ipm.note" || mi.MessageClass.ToLower() == "ipm.note.smime" || mi.MessageClass.ToLower() == "ipm.note.myclass") {
Logger.Log("Setze Message-Class auf " + MESSAGE_CLASS);
mi.MessageClass = MESSAGE_CLASS;
mi.Save();
}
} catch (System.Exception ex) {
Logger.Log("Fehler beim setzen der Message-Class:\r\n" + ex.Message);
}
}
I need to change the MessageClass, because I want to display an icon and an informationarea.
If the mail has a digital signature, the following window appears:
http://social.msdn.microsoft.com/Forums/getfile/186575
It doesn't matter which button I click, the icon doesn't changes.
Can anyone help me?
Greets Knerd
PS: Here is the question in german: http://social.msdn.microsoft.com/Forums/de-DE/vstode/thread/e51b221e-89f6-419f-90e6-e17c74662a9f
Outlook goes to great lengths to represent signed/encrypted message as regular "IPM.Note" MailItem objects (which they are not).
The only workaround I know is to bypass the OOM layer either using Extended MAPI (C++ or Delphi) or Redemption (I am its author - any language) - use RDOSession.GetItemFromID in Redemption. You can then read the MessageClass/PR_MESSAGE_CLASS property and bypass signed/encrypted messages.
Related
I'm working on WPF application in C#. Some time ago I had a problem with sending an encrypted email through the Outlook. The problem was strongly related to the encryption method - the S/MIME standard.
After that it came to my attention there's an other option for encrypting emails in the company I work for. It comes in Outlook 365 and it's called Microsoft Purview Message Encryption.
It can be enabled by choosing Encrypt-Only option under Encrypt dropdown. More here and here.
I find is very suitable for my solution as it seems to be faster and eliminates problem with expired/missing recipients' certificates.
The way I was handling the encryption so far was as follows, through the OOM, setting flags in the MailItem object:
using Outlook = Microsoft.Office.Interop.Outlook;
(...)
Outlook.Application olkApp = new Outlook.Application();
Outlook.MailItem otlMail = olkApp.CreateItemFromTemplate(templateFullPath) as Outlook.MailItem;
otlMail.To = (...)
try
{
const string PR_SECURITY_FLAGS = http://schemas.microsoft.com/mapi/proptag/0x6E010003";
long prop = Convert.ToInt64(otlMail.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS));
var ulFlags = 0x0;
ulFlags = (ulFlags | 0x1); // SECFLAG_ENCRYPTED
//ulFlags = (ulFlags | 0x2); // SECFLAG_SIGNED
otlMail.PropertyAccessor.SetProperty(PR_SECURITY_FLAGS, ulFlags);
}
catch (Exception ex)
(...)
try
{
otlMail.Send();
}
catch (Exception ex)
{
(...)
}
Unfortunately, with this way emails seems to stick with S/MIME. Even though I was trying to remove this kind of encryption through Outlook's options: (File -> Options -> Trust Center -> Email Security -> delete Default Setting), so that in new email's options was only "Encrypt-Only" option (along with Do Not Forward), and hoping the Outlook will encrypt it with new feature. Bad luck. It kept coming back.
I neither can find any useful information for developers about this feature.
Can anyone help please? Is it possible to send Encrypt-Only email through Outlook Object Model or other programming means in C#?
Regards,
Kris
The Outlook object model doesn't provide anything for that. That's an Office 365 feature (AIP).
I've a problem with my VSTO application for Outlook. I want to process the email body from a selected e-mail.
For selected e-mails out of the "default" list this code works fine:
Object selItem = Globals.ThisAddIn.Application.ActiveExplorer().Selection[1];
Outlook.MailItem mailItem = (Outlook.MailItem)selItem;
return mailItem.Body;
But if a user opens an email from the list with a double click, the email is displayed in a new window. If the addin is executed in this window (over the ribbon), the email from the list is still used (which is now in the background).
Is there a way to find out if the plugin was started in a separate window and then get the email body from it?
Regards,
Florian
Coincidentally, I just dealt with something similar to this. My situation isn't identical, but since I could easily piece together what it seems like you're looking for see below. I haven't tested this, and obviously you'll have to handle passing the correct reference to your Outlook Application, but since i had this immediately available I figured it would pass it along with the hope that you'll find it helpful.
private static void ribbonButton_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application application = new Outlook.Application();
Outlook.Inspector inspector = application.ActiveInspector();
if (application.ActiveExplorer().Selection[1] is Outlook.MailItem explorerMailItem)
{
// Write code to handle message if sourced from explorer (i.e., Reading Pane)
}
else if (inspector.CurrentItem is Outlook.MailItem inspectorMailItem)
{
// Write code to hanlde message if sourced from inspector
// (i.e., openened (double-clicked) message
}
}
When you double click on email item you open an inspector window and you can access it by using Application.ActiveInspector() method. The Inspector object has CurrentItem property which represents the opened item.
Also, you should avoid using multiple dots in expressions and properly release COM objects.
I have just started migrating to C# from VBA. I have about 100 VBA macros to convert, of which about 25 are either in a custom Ribbon entry or mapped to a keystroke, such as alt-P.
The only reference I can find says I need to retain some VBA code in order to do this. Such a solution is totally unacceptable, I have wanted to dispense with VBA entirely. I can't help thinking this is like having to keep a bale of hay in the frunk of your Tesla to feed the horse.
Is there any better way?
Press the Alt key to get the keytip reference. As per the screenshot below, I want to reference the Script Help ribbon which is Y2.
Then press Alt + Y + 2 to show the control keytip control references for that ribbon. Now I want to reference the Clean Data button which is Y7.
Then you can use SendKeys to press those keytip references. By adding the following code.
public void CallButtonFromAnotherRibbon()
{
try
{
SendKeys.Send("%");
SendKeys.Send("Y");
SendKeys.Send("2");
SendKeys.Send("%");
SendKeys.Send("Y");
SendKeys.Send("7");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Microsoft Documentation for KeyTips
Microsoft Documentation for SendKeys
Is it possible to only encrypt mail when its possible.
I wrote an Add-In which auto forward mails. The Add-In stops when it tries to encrypt a mail which cant be ecrypted. For example when there is no public key for the recipient.
I tried to catch and handle throwed exception, but in this case there is no exception thrown. Any ideas?
This is the Method I talk about.
private void signAndEncrypt(Outlook.MailItem mailItem)
{
const string PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003";
Object ulFlags = 0x3;
mailItem.PropertyAccessor.SetProperty(PR_SECURITY_FLAGS,ulFlags);
}
heres a screenshot of the error. Its in german.
error screenshot
following this link - change outlook MailItem icon
I managed to change my inbox icons.
Here's what I did step by step.
1) Created a custom message class for new mail that arrives from the Internet
The class is IPM.Note.Internet
Outlook.NameSpace outlookNameSpace;
Outlook.MAPIFolder inbox;
Outlook.Items items;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
outlookNameSpace = this.Application.GetNamespace("MAPI");
inbox = outlookNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
items = inbox.Items;
items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(items_ItemAdd);
}
void items_ItemAdd(object Item)
{
Outlook.MailItem mailitem = (Outlook.MailItem)Item;
String EmailHeader = mailitem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E");
if (Item != null && EmailHeader.Contains("Look for a string in the headers here that we set for incomming mail") == true)
{
if (mailitem.MessageClass == "IPM.Note")
{
mailitem.MessageClass = "IPM.Note.Internet";
mailitem.Save();
}
}
}
2) Created a replacement Outlook Form Region matching the MessageClass. In this case I used IPM.Note.Internet
3) Assign the Icons in the Properties Pane of the Form Region Designer.
4) Debugged project and the next message that arrived from the internet was stamped with my custom icons after the message class was updated.
My issue now is that I can't preview or open the messages where I changed the message class. Similar to this post that's unanswered - Change Inbox-icons in Outlook at runtime
I think the issue is that my replacement Outlook Form Region is blank so the message is not able to be previewed.
If this is true than here's my question. What is the best way to export the standard IPM.Note message class template into visual Studio. I thing I need to overwrite my IPM.Note.Internet Outlook Form Region design.
There is an option when creating an Outlook Form Region-
To import an ".OFS" file. I was attempting to figure out how to export the file from the Outlook 2010 Client (Developer Tools) but I can't find a way to save the templates to that specific format. I can save to OFT (office template) but not .OFS
Thanks in advance for any help!
Rather then adding a form region and changing the message class I just ended up adding the PR_ICON_INDEX property and setting it's value. As outlined here in option #2 by Dmitry Link
There are many icons to choose from here. I couldn't locate a list with the integer values so I just entered random numbers for the PR_ICON_INDEX property in Outlook Spy changing the value till located the icon I wanted. There are many icons to choose from. Many from the 600-700 and 1000 and up range.
Here's the line I used to set the PR_ICON_INDEX property on the message-
mailitem.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x10800003", 4); // change the 4 to something like 600,601...etc to experiment