Access O365 Modern Groups information from VSTO Outlook Add-in - outlook

I want to build an add-in for the MS Outlook 2019 desktop app (-> VSTO add-in). It is intended to gather some information from O365 Modern Groups that the current Outlook user (me) is a member of. As far as I understand the only way to achieve this is to use Microsoft Graph API because there is no support to access O365 related things via Outlook object model/Office Interop. Given that (and please correct me if I am wrong) I might use the Microsoft.Graph Nuget packages. With them I would like to call the following endpoint:
POST /users/{id | userPrincipalName}/getMemberGroups
possible in C# with this code snippet:
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var securityEnabledOnly = true;
await graphClient.Me
.GetMemberGroups(securityEnabledOnly)
.Request()
.PostAsync();
My question is: Is there a way of using the existing Outlook credentials for the authProvider so that I don't need the user to enter credentials?
I read that web add-ins have the possibility to use different authentication flows including a SSO flow. But that does not fit for VSTO.
I thought of a IntegratedWindowsAuthenticationProvider. But therefore I need to provide a clientId which I do not have. Does that ultimately mean that I need to register my add-in in some way? Can't I just write an add-in for my personal purposes without admin support?
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create(clientId)
.WithTenantId(tenantID)
.Build();
IntegratedWindowsAuthenticationProvider authProvider = new IntegratedWindowsAuthenticationProvider(publicClientApplication, scopes);

Related

How to send an email from an outlook office add on?

I am trying to build an outlook add on, using react. I looked everywhere trying to find something that uses the mailbox in which the addon has been opened from, to programmatically send an email to a specified user.
Something similar to the google's command:
GmailApp.createDraft(e.parameters.address, e.parameters.subject, e.parameters.body, {
htmlBody: e.parameters.body,
name: 'Automatic Sender'
}).send();
Is the mail-sending process available on outlook?
Outlook web add-ins work under the context of currently selected item only. OfficeJS doesn't provide anything for creating and sending emails programmatically.
In Outlook add-ins you may consider using EWS, see Call web services from an Outlook add-in for more information. Also you may take a look at the Graph API as a possible workaround.

Can Microsoft Outlook Policy Tips be used in conjunction with add-ins REST/EWS send API?

I have a scenario where a "compose mode" add-in for Outlook makes a subject line update to the draft email, then sends the email. The send action is currently carried out using either the EWS or REST APIs.
The issue occurs when a "override" policy tip is configured by the Exchange admin. The policy tip in question requires the user to choose override, in certain cases, to send an email (e.g external communication).
During message composition, if the appropriate trigger for the policy tip occurs, the policy tip appears and offers the user the option to override (as expected). When the add-in action is called, via ribbon button, the email appears to be sent. However, moments later an automated message from the Exchange indicates that the email has not been sent due to not adhering to the policy rule.
I believe this occurs because the send API, for both EWS and REST, does not call a local function in the Outlook client. Rather these API actually perform the send event on an email item syncedto and stored on the server. The Exchange server has no knowledge of the user's selection to override the policy tip at the client, so the issue occurs.
This happens in both Outlook on Desktop and Outlook Web Access.
I have searched through the EWS and REST APIs and cannot find any way to share/indicate the policy tip override when using these API.
I have searched the add-ins developer documentation and can find no mention of policy tips at all.
I have searched the Exchange admin policy tips documentation and can find no mention of add-ins compatibility or add-in related behavior.
So, can Microsoft Outlook Policy Tips be used in conjunction with add-ins REST/EWS send API?

Is there an Outlook Javascript API to get control to addin on Saving as Draft or before syncing to server?

I am working on an Outlook addin to make sure confidential information is not leaked using mail.
Using the on-send feature using ItemSend, we were able to get the email fields and block the sendmail, if required
https://github.com/OfficeDev/Outlook-Add-in-On-Send/tree/master/outlook-add-in-on-send
But there is an use case
User composes the mail and saves it to draft (without clicking on Send)
In outlook on web, composing a mail saves to draft automatically.
How can the add-in get a callback when draft is synced to Outlook server ?
How can the add-in get a callback when draft is synced to Outlook server ?
There is no such callback available for web add-ins. You may post a feature request or suggest a feature on the Tech Community site where community members get to share ideas on ways MS can make Microsoft Graph and Office Platform better by sharing feature requests and ideas.
Nothing like that for the JS-based addins.
For the COM addins, OOM exposes MailItem.Write event - your event handler can cancel the operation.

CRM 2011 Outlook Client open custom web app, both sites using ADFS authentication

Currently I'm working on a task to fix the process of opening custom web page in outlook client from custom ribbon button, it's similar to this question:
JavaScript pop-up in Dynamics CRM 2011 Outlook client
client
However, I have configured the website to have the same authentication token from the same ADFS as CRM web. If I open it using IE/any other web browsers (in UR 12), it works fine. If I open it using outlook client, it keep prompting the user to authenticate (which is quite annoying for some users).
I've read these, but they are only applicable for CRM form, not custom web app:
ADFS (CRM 2011) - Authentication Issue in Microsoft Outlook Client for CRM (Response.Redirect(...) & Window.Open(...))
http://msdn.microsoft.com/en-us/library/jj602956.aspx
Anyone have any idea on this?
FYI, I'm using CRM 2011 UR 12, and Outlook 2010 with CRM client.
TIA
I ended-up using openStdWin, based on: http://blog.customereffective.com/blog/2011/12/jscript-pop-up-in-crm-402011-internet-explorer-vs-outlook.html and Dieter's comment. It still asked me to authenticate once, even though I've provided the login detail in outlook client setup.
The javascript function:
function openNewWindow(url) {
var name = "newWindow";
var width = 800;
var height = 600;
var newWindowFeatures = "status=1";
var oldWindowFeatures = "width=800,height=600,status=1";
// Regular Jscript function to open a new window
//window.open(url, name, oldWindowFeatures);
// CRM function to open a new window
openStdWin(url, name, width, height, newWindowFeatures);
// CRM function to open a new window
// with default CRM parameters
//openStdWin(url, name);
}

Send outlook appointment through asp.net error HRESULT: 0x80004004

I am trying to send an outlook appointment through code. My code is posted below. When I run it on the server with IIS 6 and an app pool under a domain account identity, it throws this error. I have tried changing various settings on the server and none worked. Outlook 2007 is installed. I have even made the domain account a local admin. Please help!
Description: An unhandled exception
occurred during the execution of the
current web request. Please review the
stack trace for more information about
the error and where it originated in
the code.
Exception Details:
System.Runtime.InteropServices.COMException:
Operation aborted (Exception from
HRESULT: 0x80004004 (E_ABORT))
Line 201: objAppt.Send();
Code below:
Microsoft.Office.Interop.Outlook.Application objOL
= new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.AppointmentItem objAppt
= (Microsoft.Office.Interop.Outlook.AppointmentItem)objOL
.CreateItem
(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
objAppt.Start = startTime;//datetime
objAppt.End = endTime;//datetime
objAppt.Subject = subject;
objAppt.Body = body;
objAppt.Location = location;
objAppt.MeetingStatus
= Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
objAppt.RequiredAttendees = "test#test.com";
objAppt.Send();
objAppt = null;
objOL = null;
Yes as casperOne said I wouldn't use outlook on the server. I would use CDO or RDO(redemeption) for this. or even use vcal and send the vcal on a system.Net.Mail.
Update:
Take a look at http://www.dimastr.com/redemption/rdo/RDOAppointmenItem.htm
Show you how to do excatly what you want to do using RDO. You can do the same with CDO as well. Check out CDOLive.com
You will have to construct a teh login details as you are on a server that has no Outlook profile (thats if you remove the one that you allready have on there)
Quite simply, you shouldn't be doing this. It is not recommended that you run Office in a server environment because of the threading (and desktop session) requirements that Office has.
Are you trying to do this on an Exchange server? If so, then I would interact directly with the Exchange server (using WebDAV perhaps?).
If not connecting with Exchange, then take a look at the headers for an invitation to the event. The invitations should be nothing more than regular emails with custom header information.
I guess the reason you cannot use Outlook from an IIS application is because the current user the IIS app is running under does not have an Outlook profile associated.
Therefore you can instantiate Outlook objects and set their properties, until profile-specific functionality is required, such as the Send() command, which would store the outgoing mail in the user's/profile's (non-existing) pst file.
Don't do this using Outlook automation.
Straight from the horse's mouth:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
http://support.microsoft.com/kb/257757
Examine email headers sent by Outlook when it's doing this job to work out how this is done, and emulate it using the standard .NET SmtpClient stuff.

Resources