コード例 #1
0
        public static async Task <string> ReadMessage(string AccessToken, string userid, string mailfolderid)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            getmessages mailmessagedetails = new getmessages();

            var url = $"https://graph.microsoft.com/beta/users/{userid}/mailFolders/{mailfolderid}/messages?filter=startswith(subject,'Output')";

            JObject mailmessage = await apiCaller.CallGetWebApiAndProcessResultASync(url, AccessToken);

            IList <JToken>      mailmessages       = null;
            IList <getmessages> mailmessageresults = null;

            mailmessages = mailmessage["value"].Children().ToList();
            if (mailmessages.Count > 0)
            {
                mailmessageresults = new List <getmessages>();

                foreach (JToken res in mailmessages)
                {
                    mailmessagedetails = res.ToObject <getmessages>();
                    mailmessageresults.Add(mailmessagedetails);
                }
                await DeleteMessage(AccessToken, userid, mailmessagedetails.id);

                return(mailmessagedetails.body.content);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public static async Task DeleteMessage(string AccessToken, string userid, string messageid)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            var url = $"https://graph.microsoft.com/beta/users/{userid}/messages/{messageid}";

            JObject mailmessage = await apiCaller.CallDeleteWebApiAndProcessResultASync(url, AccessToken);
        }
コード例 #3
0
        //#region MailFolderCreation
        //public static async Task<string> CreateFolder(ClientCredentialProvider authProvider, string uid)
        //{

        //    GraphServiceClient graphClient = new GraphServiceClient("https://graph.microsoft.com/beta", authProvider);

        //    MailFolder CreatemailFolder = new MailFolder()
        //    {
        //        DisplayName = "Demo"
        //    };

        //    MailFolder createFolder = await graphClient.Users[uid].MailFolders
        //        .Request()
        //        .AddAsync(CreatemailFolder);

        //    return createFolder.Id;

        //}
        //#endregion MailFolderCreation

        #region MessageCreation

        public static async Task SendMessage(string AccessToken, string userid, string mailfolderid, string value)
        {
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            var            url = $"https://graph.microsoft.com/beta/users/{userid}/mailFolders/{mailfolderid}/messages";
            createmessages createmailmessagedetails = new createmessages();

            messagebody body = new messagebody();

            body.contentType = "Text";
            body.content     = value;

            createmailmessagedetails.subject = "Input";
            createmailmessagedetails.body    = body;

            string data = JsonConvert.SerializeObject(createmailmessagedetails);


            JObject createmailmessage = await apiCaller.CallPostWebApiAndProcessResultASync(url, AccessToken, data);
        }
コード例 #4
0
        public static async Task <string> GetUserID(string AccessToken, string user)
        {
            #region GetUserID
            var httpClient = new HttpClient();
            var apiCaller  = new ProtectedApiCallHelper(httpClient);

            getuserid userid = new getuserid();
            var       url    = $"https://graph.microsoft.com/beta/users?$select=id&$filter=startswith(displayname, '{user}')";
            JObject   users  = await apiCaller.CallGetWebApiAndProcessResultASync(url, AccessToken);

            IList <JToken> userresults = users["value"].Children().ToList();

            IList <getuserid> usersearchResults = new List <getuserid>();
            foreach (JToken res in userresults)
            {
                userid = res.ToObject <getuserid>();
                usersearchResults.Add(userid);
            }
            return(userid.id);

            #endregion GetUserID
        }