I am trying to create an application that subscribes to mail events (New mails, Create,update) in office 365 using Microsoft Graph APIs without user interaction. If there is a new email I want to send a notification to my app which has been built using C# MVC5 and .Net 4.5. An example I am following is in Github here (using Daemon Service
Github project Link)
but it has been built in .Net Core. I came across another application which uses WebJobs and is very close to my requirement
Azure webjobs but it has not been updated in the last 2 years. I followed the steps but most of them do not match with my Azure Developer Account (free). Can some one help me on this please?
App settings :
App Settings:
<add key="tenantId" value="[Tenant_ID]" />
<add key="clientId" value="[AppID]" />
<add key="clientSecret" value="[Client Secret]" />
<add key="webjobs" value="DefaultEndpointsProtocol=https;AccountName=onvidawebjob1aa1b;AccountKey=Z3xewALbEc43gE/dL06HxCGIjVtpaiTkIY4ZolkjZt9Z86xHIZLzMwXBlujNI8/PcTJbM1LIs5KNceVTGgESmA==" />
<add key="subscriptionblobname" value="subscriptions/subscription1" />
<add key="notificationurl" value="https://onvidawebjob1.azurewebsites.net/api/HttpTrigger1?code=H7liZOlcQc5qjcZOkRXEb0x4JVqTzoXnrl6mAswsEKl4LlmAYm/ACw==" />
i tried to recreate the app got below issue Trace
Development settings applied
Found the following functions:
WebHooksSample.Functions.ManageSubscriptions
WebHooksSample.Functions.OnNotificationReceived
Singleton lock acquired (cd016b3464fa4d8aa8f41f884a064168/WebHooksSample.Functions.ManageSubscriptions.Listener)
Function 'WebHooksSample.Functions.ManageSubscriptions' is configured to run on startup. Executing now.
Executing 'Functions.ManageSubscriptions' (Reason='Timer fired at 2018-11-16T19:05:27.4182054+05:30', Id=155f7f8a-c352-427f-a7c3-a55ab3518c9a)
Exception while executing function: Functions.ManageSubscriptions
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ManageSubscriptions ---> System.Net.Http.HttpR
equestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at WebHooksSample.Functions.<ManageSubscriptions>d__14.MoveNext() in D:\354132\office365_sample_app\webjobs\webjobs-webhooks-sample-master\WebHooks
Sample\Functions.cs:line 128
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.<InvokeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<InvokeAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatchersAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
--- End of inner exception stack trace ---
Exception while executing function: Functions.ManageSubscriptions
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ManageSubscriptions ---> System.Net.Http.HttpR
equestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at WebHooksSample.Functions.<ManageSubscriptions>d__14.MoveNext() in D:\354132\office365_sample_app\webjobs\webjobs-webhooks-sample-master\WebHooks
Sample\Functions.cs:line 128
--- End of stack trace from previous location where exception was thrown ---
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionInvoker`1.<InvokeAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<InvokeAsync>d__22.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithWatchersAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at `enter code here`System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__19.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<ExecuteWithLoggingAsync>d__13.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Azure.WebJobs.Host.Executors.FunctionExecutor.<TryExecuteAsync>d__10.MoveNext()
The next 5 occurrences of the schedule will be:
11/16/2018 7:06:03 PM
11/16/2018 7:06:33 PM
11/16/2018 7:07:03 PM
11/16/2018 7:07:33 PM
11/16/2018 7:08:03 PM
Job host started
Executing 'Functions.ManageSubscriptions' (Reason='Timer fired at 2018-11-16T19:05:57.4122054+05:30', Id=405fe97b-2b8a-48bb-a761-7c46a293622c)
Exception while executing function: Functions.ManageSubscriptions
Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: Functions.ManageSubscriptions ---> System.Net.Http.HttpR
equestException: Response status code does not indicate success: 400 (Bad Request).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at WebHooksSample.Functions.<ManageSubscriptions>d__14.MoveNext() in D:\354132\office365_sample_app\webjobs\webjobs-webhooks-sample-master\WebHooks
Sample\Functions.cs:line
EDIT 1:
I was able to accomplish receiving emails (without a user logging in) using outlook connector and office 365 webhook API (using default connector available in azure logic App) similar to what is described here. However, outlook connector polls for every x seconds (custom value set by me) for any change in the mailbox, but I want the service to automatically trigger the Webhook Event without polling. If I understand it correctly, it should be like this -
Create a webhook that is registered to watch for events
Create an outlook connector that uses above webhook.
Outlook connector notifies application (REST API call) as part of workflow.