コード例 #1
0
        public static bool Send(string Subject, string Message, string[] Recipient, FoodConfig config)
        {
            var result = false;

            var recipients = new List <Recipient>();

            foreach (var r in Recipient)
            {
                AddReciepient(recipients, r);
            }


            var body = new ItemBody
            {
                ContentType = BodyType.Html,
                Content     = Message,
            };

            Message message = new Message
            {
                Subject      = Subject,
                Body         = body,
                ToRecipients = recipients,
            };

            // config.returnUrl = config.App.FrontendUrl;
            sendMail(config.GraphCfg, message, config.App.MailSender);

            result = true;
            return(result);
        }
コード例 #2
0
        private static void send(FoodConfig cfg, Message msg)
        {
            IConfidentialClientApplication confidentialClientApplication = ConfidentialClientApplicationBuilder
                                                                           .Create(cfg.AppReg.clientId)
                                                                           .WithTenantId(cfg.AppReg.tenantId)
                                                                           .WithClientSecret(cfg.AppReg.clientSecret)
                                                                           .Build();

            ClientCredentialProvider authProvider = new ClientCredentialProvider(confidentialClientApplication);

            GraphServiceClient graphClient = new GraphServiceClient(authProvider);

            graphClient.Users[cfg.App.mailSender].SendMail(msg, false).Request().PostAsync();
            List <QueryOption> options = new List <QueryOption> {
                new QueryOption("$top", "1")
            };

            var graphResult = graphClient.Users.Request(options).GetAsync().Result;
        }