Exemplo n.º 1
0
        static async void SendEmail(CaptchaMessage message)
        {
            var            apiKey  = "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";
            SendGridClient SClient = new SendGridClient(apiKey);

            try
            {
                var msg = new SendGridMessage()
                {
                    From = new EmailAddress("*****@*****.**", "Mailroom Service")
                };
                msg.SetTemplateId("9cba370f-5cf1-4a44-b73a-c7c2fe6e22c3");

                msg.AddTo(message.Alias + "@microsoft.com");

                msg.AddSubstitutions(new Dictionary <string, string>()
                {
                    { "-alias-", message.Alias },
                    { "-captcha-", message.Captcha }
                });

                await SClient.SendEmailAsync(msg);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        static void StartMessageListening()
        {
            if (QClient == null)
            {
                var connectionString = ConfigurationManager.AppSettings["QueueConnectionString"];
                var queueName        = ConfigurationManager.AppSettings["QueueName"];

                QClient = QueueClient.CreateFromConnectionString(connectionString, queueName);
            }

            QClient.OnMessage(messageString =>
            {
                CaptchaMessage message = JsonConvert.DeserializeObject <CaptchaMessage>(messageString.GetBody <string>());

                SendEmail(message);
            });
        }