Get/change safe senders list and blocked senders list in C# VSTO - outlook

I'm working on an Outlook 2010 add-in that needs to prompt users before following a link found in an email. During the process I'd like to offer the user the choice to trust or block the sender of the email, thus I need to access both lists. I realize that Junk/Spam email options are not exposed by Outlook OM. Although I was successful in accomplishing the task using Redemption, unfortunately I'm not allowed to use it by my employer, so I need to find another way. I found this post (Get Safe sender list in Outlook 2007 C# Add in) that points in the direction of either MAPI properties or registry keys.
My preference would be MAPI props, but I'm not sure what object that property belongs to. Would it be the property of the default store?
Outlook.Store obj = Application.Session.DefaultStore;
const string PR_SPAM_TRUSTED_SENDERS_W =
"http://schemas.microsoft.com/mapi/proptag/0x001f0418";
Outlook.PropertyAccessor pa = obj.PropertyAccessor;
string list= pa.GetProperty(PR_SPAM_TRUSTED_SENDERS_W).ToString();
Unfortunately I'm getting an error message (translated to English) like 'Object doesn't have such property'. In production it would have to work with Outlook clients connected to Exchange 2007 mailboxes.

Ok found it. The actual property is called PidTagExtendedRuleMessageCondition and the Blob format is described here MS-OXCSPAM and in MS-OXORULE respectively.

Related

Changing Account with "on-send" feature?

I have a customer with multiple users, they have two emails accounts on two differents domains.
One is managed by Office365 : Teams / Calendar, example : #my-business.com
Second is for "secure" communication, exemple : #my-secure-email.com
The second one is really not used very often but the emails sent or received must absolutely not go on Office365 (legal reason)
I want to force user to send emails to *.#my-secure-email.com with second account.
With "on-send Feature" i think i can "block" emails but ideally it should be possible to dynamically change the account used in Outlook according to the recipient's address ?
EDIT to clarify :
Is it possible to change sender account with office-js and "on sender" feature on office365 ?
Is it possible to change sender account direclty in Outlook for Windows based on recipient address ?
Thanks
Guldil
Is it possible to change sender account with office-js and "on sender" feature on office365 ?
No, it is not possible. OfficeJS doesn't provide anything for that.
Is it possible to change sender account direclty in Outlook for Windows based on recipient address ?
Yes, you can choose the sender's account in Outlook manually or by using a VSTO add-in instead. The MailItem.SendUsingAccount property is available in the Outlook object model (available for VBA macros and COM based add-ins). The property allows setting an Account object that represents the account under which the MailItem is to be sent.
But web add-ins work under the context of currently selected item only (or in case of UI-less add-ins what they activated for) and don't provide access to application-wide features like choosing email account to send from.
You can post or vote for an existing feature request on Tech Community where they are considered when the Office dev team go through the planning process. Use the github label: Type: product feature request at https://aka.ms/M365dev-suggestions .

VSTO Identify shared vs User mailbox

In a VSTO add-in, I am trying to retrieve if the type of the mailbox is shared, user or resource.
I read some interesting posts related to the question and try to look at the OlExchangeStoreType or GetConversation or MailboxType but did not succeed.
I have seen the solution (3) from #DmitryStreblechenko but I would prefer to not use EWS if possible.
It seems that the value that I am looking for is the msExchRecipientTypeDetails.
Any help would be highly appreciated.
Relevant articles
EWS Get mailbox type (user/resource/shared)
MailItem.GetConversation() on shared mailbox
In Outlook Addin, how do I determine if an email's Sender is a shared mailbox email address?
https://www.codeproject.com/Questions/1088741/How-to-list-subfolders-in-inbox-folder-in-shared-e
https://learn.microsoft.com/en-us/answers/questions/612248/in-outlook-addin-how-do-i-determine-that-an-email.html
First of all, VSTO doesn't provide anything for that.
Second, the Outlook object model doesn't differentiate shared/local stores. So, you will not find any property or method for that in the OOM. The best what you could do is to use the Store.ExchangeStoreType property which returns a constant in the OlExchangeStoreType enumeration that indicates the type of an Exchange store.
It is up to you which way/workaround is to use form the list shared above.
You don't need to use EWS - try to read Namespace.AutoDiscoverXml property to check if the shared mailbox and its type are there - you can see it in OutlookSpy (I am its author): click Namespace button, select AutoDiscoverXml property.
Look for the AlternativeMailbox\Type nodes - you can have "Archive", "Delegate", "TeamMailbox".

Log incoming and outgoing emails using Outlook web add-in

I have a working VSTO COM based Outlook add-in that intercepts all incoming/outgoing emails on a desktop outlook which is then used to save the details of the email into a SQL database. Below is a brief description of the steps I take using the add-in:
Intercept an incoming/outgoing email and adds a custom GUID as a user property on the email
Calls an end-point to my custom Web API on the cloud and sends an XML with details like the GUID (saved above) and other mail related ids and details
The API end-point saved the details into a SQL database and returns the response back to Outlook so that Outlook doesn't freeze up
A windows service runs in the background and monitors this SQL database for email items and makes a Web API call to Exchange or Office 365 to find the email using the GUID user property and then save it where needed.
I cannot save the email directly via the API call from VSTO add-in since there is some custom time-consuming logic that happens in the API so I cannot keep Outlook frozen for that time.
Is it possible to create something similar using the newer Outlook Web Add-in?
Kind of - you can intercept outgoing messages, but if you do, your addin won't be eligible to be published in the store.
It is still much easier in a VSTO addin. You cannot access Outlook Object Model from a secondary thread, but you can still run your code that does other things. Once you are done, you can access OOM on the main thread by opening message that you need to process by its entry id saved before you started the secondary thread. Note that the inability to access various objects from a secondary thread is OOM specific - Extended MAPI objects can be accessed from secondary threads, but Extended MAPI requires C++ or Delphi. In other languages (including all .Net languages), you can use Redemption (I am its author) and its RDO family of objects - all you need to do is save the value of the Application.Session.MAPIOBJECT property in a dedicated variable, then on a secondary thread create an instance of the RDOSession object and set its MAPIOBJECT property to the variable you saved on the main thread (see http://www.dimastr.com/redemption/faq.htm#Threads for more details).

Outlook New Message - Text Area Below Toolbar

I am creating an addin for Outlook.
I want to check some text on sending, but im not sure how to reference it
The text is in the image below and says “Attachment will be sent using...”
If the text equals the text displayed, i want to do something.
Thanks for any advice.
The Outlook object model doesn't provide anything for reading mail tips. But you may consider using EWS for getting mail tips. See Using MailTips in EWS to get the OOF (Out of Office) Status of users with C# and Powershell for the sample code.
FYI MailTips are informative messages displayed to users in the infobar in Outlook Web App and Outlook 2010/2013/2016 when a user does any of the following while composing an e-mail message:
Add a recipient
Add an attachment
Reply or Reply all
Open a message from the Drafts folder that's already addressed to recipients
To configure MailTips for mailboxes, external contacts, and distribution groups, in the Exchange Control Panel, select the mailbox, external contact, or distribution group, click Details, and then in the MailTip section, create the MailTip.
To configure MailTips for mail users and dynamic distribution groups, in Windows PowerShell, use the MailTip parameter on the Set-MailUser and Set-DynamicDistributionGroup cmdlets.
Regardless of whether you use the Exchange Control Panel or Windows PowerShell, two things always happen when you add a MailTip to a recipient:
HTML tags are automatically added to the text. For example, if you enter the following text: This mailbox is not monitored. The MailTip automatically becomes the following: <html><body>This mailbox is not monitored.</body></html>
The text is automatically added to the MailTipTranslations property as the default value. If you modify the MailTip text, the default value is automatically updated in the MailTipTranslations property.
Read more about that in the Configure MailTips article.

How can we force a mailbox item to be persisted to EWS?

Note: This particular issue has significant impact on our customers, which translates to high business impact with direct consequences on revenue.
TL;DR.
How can our Office add-in for Outlook, when a user interacts with our add-in while composing an email draft, minimize the amount of time it takes before the EWS GetItem API will return an OK response for the itemId we receive from Office.context.mailbox.item.saveAsync()?
If it turns out that our add-in has no control over when the item will be persisted to EWS, then what could an end-user do to speed this up?
We are looking for either (a) a technical solution, or (b) messaging to instruct our customers on how to mitigate/fix/work around this issue.
End-User Impact
Some of our customers are unable to send emails using our Office add-in for Outlook, or have to wait an exceedingly long time (> 2 minutes) before their email will send.
Our Goal
We want all of our customers to be able to send emails using our add-in, without having to wait for an unreasonable amount of time.
Additional Context
Based on our logs and customer reports, this issue only exists in the Outlook 2016 for Windows desktop application. We have no evidence to suggest the issue is present in any other version of Outlook, including Outlook 2013 or Outlook for Mac, however it is possible that the issue may be present in those clients as well.
Overview of our add-in
Our add-in integrates with Compose mode to provide additional functionality while composing email messages, such as templates, follow-ups, open and click tracking, and scheduling.
Our add-in works in tandem with our SaaS product like this:
Our add-in sets EWS extended properties on the email message with metadata indicating which features are enabled on that message.
Our SaaS product, out of band, is configured to read from the customer's mailbox via the EWS API. When it encounters EWS extended properties our Office add-in has written, it triggers the code paths to satisfy the desired behavior.
Root Cause Analysis
The root cause of our problem is our interaction with EWS in Outlook 2016 for Windows. In order to successfully interact with EWS to read/write to a mailbox item, it must be aware of that item.
The documentation for Office.context.mailbox.item.saveAsync() says:
In Outlook Web App or Outlook in online mode, the item is saved to the server. In Outlook in cached mode, the item is saved to the local cache.
It goes on further to say:
Note: If your add-in calls saveAsync on an item in compose mode in order to get an itemId to use with EWS or the REST API, be aware that when Outlook is in cached mode, it may take some time before the item is actually synced to the server. Until the item is synced, using the itemId will return an error.
Thus, we have concluded that Office.context.mailbox.item.saveAsync(), although it does indeed return an eventually valid itemId, does not guarantee that any subsequent EWS interaction will succeed. So far, we have found no way to accelerate the process of the Outlook client actually making EWS aware of the mailbox item.
Mitigation
We have attempted to mitigate this problem by polling EWS GetItem to attempt to obtain a ChangeKey for the item with the itemId we receive from Office.context.mailbox.item.saveAsync(). While we have seen that this does eventually succeed, it may take a minute or longer before this occurs. That is simply far too much time for our customers to have to wait.
Understanding "online mode" vs "cached mode"
If the Outlook 2016 for Windows desktop client is in "cached mode", is there anything the user can do to:
…know whether the client is in "cached mode" or "online mode"?
…attempt to force the client into "online mode"?
There is no way to speed this up in cached mode. Unfortunately this is a limitation of saveAsync in compose mode. Some things of note:
1) The EWSId is only valid while the item is a draft. After it is sent, when the item is in sent items, it will have a new EWSId which is not obtainable from the Office.js
2) Could you save your information into the custom properties, instead of the EWS Extended Properties. (Office.context.mailbox.item.customProperties) https://dev.office.com/reference/add-ins/outlook/1.5/CustomProperties?product=outlook
These properties will be saved to the mail in the sent item, but will NOT be transmitted. Then could you find those properties
These are stored as a JSON dictionary on the item in Key/Value pairs. The name of the mapi property is "cecp-[extension id from manifest]" (in PS_PUBLIC_STRINGS)
https://msdn.microsoft.com/en-us/library/office/cc842512.aspx
3) It does kind of sound like a better way to solve this would be an Office.js function that gives write access to this? (though we don't completely understand your scenario). Request for new features should go through UserVoice:
https://officespdev.uservoice.com/forums/224641-general/category/131778-outlook-add-ins.
4) Being in Online Mode would greatly mitigate the time. A User can know whether or not he or she is in online mode, but an Add-in cannot.
https://support.office.com/en-us/article/Turn-on-Cached-Exchange-Mode-7885af08-9a60-4ec3-850a-e221c1ed0c1c
Additionally, the status bar will say "Connected to Microsoft Exchange" in cached mode, and "Online with Microsoft Exchange" in online mode.
Switching to Online mode, removes a lot of the benefits that cached mode has. Cached mode is default in Outlook 2016.

Resources