Exemple #1
0
        public async Task <ActionResult> SendMessageSubmit(UserInfo userInfo)
        {
            // After Index method renders the View, user clicks Send Mail, which comes in here.
            EnsureUser(ref userInfo);
            SendMessageResponse sendMessageResult = new SendMessageResponse();
            // Send email using the Microsoft Graph API.
            var token = Data.GetUserSessionTokenAny(Settings.GetUserAuthStateId(ControllerContext.HttpContext));

            if (token.Provider == Settings.AzureADAuthority || token.Provider == Settings.AzureAD2Authority)
            {
                sendMessageResult = await GraphApiHelper.SendMessageAsync(
                    token.AccessToken,
                    GenerateEmail(userInfo));
            }
            else if (token.Provider == Settings.GoogleAuthority)
            {
                sendMessageResult = await GoogleApiHelper.SendMessageAsync(token.AccessToken, GenerateEmail(userInfo), token.Username);
            }
            // Reuse the Index view for messages (sent, not sent, fail) .
            // Redirect to tell the browser to call the app back via the Index method.
            return(RedirectToAction(nameof(Index), new RouteValueDictionary(new Dictionary <string, object> {
                { "Status", sendMessageResult.Status },
                { "StatusMessage", sendMessageResult.StatusMessage },
                { "Address", userInfo.Address },
            })));
        }