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
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 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?
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 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.
is there a way i can receive messages using SKYPE4COM .dll? I am sending messages to a specific user using skype.SendMessage(). How can i receive them? I am working in a form application in visual studio c# and i would like to make a windows form to pop up everytime i receive a message. I amusing skype4com.dll. Please help.
Can you please write a little code that was testes and works? thx
The official example is for Delphi: http://developer.skype.com/delphi-examples/chatmessages-pas
But you do it in the same way. Simply subscribe on the OnMessageStatus event.
did a bit of googling:
http://www.youtube.com/watch?v=8CMuSXQDMYs
http://www.codeproject.com/KB/cs/SkypeBot.aspx?q=skype4com+message+event+c%23
I know the answer is very late but I think the code can help other programmers having the same problem (code from vsnippets.com):
Skype skype = new Skype();
skype.MessageStatus += new _ISkypeEvents_MessageStatusEventHandler(incommingMessage);
private void incommingMessage(ChatMessage msg, TChatMessageStatus status)
{
string sender = msg.Sender.Handle; // Skype name of sender!
string message = msg.Body; // Message content
DateTime sendTime = msg.Timestamp; // Time when the sender has sended the message.
MessageBox.Show(String.Format("Your contact {0} sended you a message at {1}:\n\n{2}", sender, sendTime.ToString("yyyy-MM-ddTHH:mm:ss.fff"), message), "New Message");
}
(Code not tested yet but it should work)