Esempio n. 1
0
        // Create the mail structure needed to make a request to the Microsoft Graph
        public static MailModel CreateMail(string subject, string body, params string[] recipients)
        {
            var mail = new MailModel
            {
                Message = new MessageModel
                {
                    ToRecipients = recipients.Select(recipient => new ToRecipientModel
                    {
                        EmailAddress = new EmailAddressModel
                        {
                            Address = recipient
                        }
                    }).ToList(),
                    Subject = subject,
                    Body    = new BodyModel
                    {
                        ContentType = "html",
                        Content     = body
                    }
                }
            };

            return(mail);
        }
Esempio n. 2
0
 // Create the mail structure needed to make a request to the Microsoft Graph
 public static MailModel CreateMail(string subject, string body, params string[] recipients)
 {
     var mail = new MailModel
     {
         Message = new MessageModel
         {
             ToRecipients = recipients.Select(recipient => new ToRecipientModel
             {
                 EmailAddress = new EmailAddressModel
                 {
                     Address = recipient
                 }
             }).ToList(),
             Subject = subject,
             Body = new BodyModel
             {
                 ContentType = "html",
                 Content = body
             }
         }
     };
     return mail;
 }
Esempio n. 3
0
        // Send a mail using a prepared HttpClient (with an authorization header)
        private static async Task<bool> SendMailAsync(HttpClient httpClient, MailModel mail)
        {
            // Serialize the mail
            var stringContent = JsonConvert.SerializeObject(mail);

            // Send using POST
            var response = await httpClient.PostAsync(GraphResource + GraphVersion + "/me/microsoft.graph.sendMail",
                new StringContent(stringContent, Encoding.UTF8, "application/json"));
            return response.IsSuccessStatusCode;
        }