예제 #1
0
        public async Task <bool> SendEmail(string toEmail, string emailTemplate, Dictionary <string, string> bodyReplacementValues,
                                           Dictionary <string, string> subjectReplacementValues)
        {
            var hermesApi          = ConfigurationManager.AppSettings["HermesApi"];
            var applicationId      = Convert.ToInt16(ConfigurationManager.AppSettings["ApplicationId"]);
            var authorizationToken = ConfigurationManager.AppSettings["EmailAuthorizationToken"];
            var sendEmails         = Convert.ToBoolean(ConfigurationManager.AppSettings["SendEmails"] ?? "false");
            var sendEmailClient    = new SendEmailClient(hermesApi);

            if (sendEmails)
            {
                if (!String.IsNullOrEmpty(toEmail))
                {
                    var emailItem = new EmailItem
                    {
                        ToEmail                  = toEmail,
                        ApplicationId            = applicationId,
                        EmailTemplate            = emailTemplate,
                        AuthorizationToken       = authorizationToken,
                        ReplacementValues        = bodyReplacementValues,
                        SubjectReplacementValues = subjectReplacementValues
                    };

                    await sendEmailClient.SendEmailAsync(emailItem);

                    return(true);
                }

                return(false);
            }

            return(false);
        }
예제 #2
0
        public async Task SendEmailClientAsyncShouldWork()
        {
            var sender = new SendEmailClient(this.Configuration["SendGrid:ApiKey"]);

            using var consoleText = new StringWriter();
            Console.SetOut(consoleText);
            await sender.SendEmailAsync("*****@*****.**", "goshko", "*****@*****.**", "zaglavie", "tainbrat");

            Assert.Equal("Accepted", consoleText.ToString().Trim());
        }
예제 #3
0
 public async Task SendEmailClientAsyncShouldThrowException(string data)
 {
     var sender = new SendEmailClient(this.Configuration["SendGrid:ApiKey"]);
     await Assert.ThrowsAsync <ArgumentException>(() => sender.SendEmailAsync("*****@*****.**", "goshko", "*****@*****.**", data, data));
 }