There is a warning when you send emails via Outlook by using the Microsoft.Office.Interop.Outlook objects. There are several workarounds in form of disabling the complete security warning. That is not applicable in our case. The other options seems to set the protocol used to a registry key.
So if you add a key like HKCU/SOFTWARE/Microsoft/Office/16.0/Common/Security/Trusted Protocols/All Applications/foo: then all calls from the foo:// protocol are trusted and no warning pops up.
We use a code like this:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application _outlook = new Outlook.Application();
Outlook.MailItemn _message = null;
...
_message = (Outlook.MailItem)_outlook.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Recipients recipients = _message.Recipients;
if (!string.IsNullOrEmpty(MailTo))
{
string[] mailToList = MailTo.Split(';');
foreach (string mailToEntry in mailToList)
{
Outlook.Recipient recipient = recipients.Add(mailToEntry.Trim());
recipient.Type = (int)Outlook.OlMailRecipientType.olTo;
recipient.Resolve();
}
}
foreach (MailAttachment attachment in Attachments)
{
string tempDir = TempDirectory.Create();
string tmpFile = Path.Combine(tempDir, attachment.Name);
File.WriteAllBytes(tmpFile, attachment.Data);
_message.Attachments.Add(tmpFile, (int)Outlook.OlAttachmentType.olByValue, 1, attachment.Name);
}
_message.Send();
At least in a shorted form. My question is now: "How could I define this in the registry as exception?"
Maybe it is possible to create something like HKCU/SOFTWARE/Microsoft/Office/16.0/Common/Security/Trusted Protocols/MyApp/http:?
This does not work, because the protocol used seems not to be http. Does someone know which one is used here and maybe how to change the name so we could use it in the exception settings?
Has anyone an idea?