예제 #1
0
        [Fact]//(Skip = "Test to see if mail is inboxed")]
        public async Task EmailSenderShouldSendWithTemplate()
        {
            var factory = new SendGridMailFactory(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Test",
                Templates       = new List <TemplateItem>()
                {
                    new TemplateItem()
                    {
                        Id   = "7cc262f1-48eb-4948-a22c-16cb844d4540",
                        Type = NotificationType.ResetPassword
                    }
                }
            }));
            var sender = new SimpleSendGridEmailSender(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                ApiKey          = "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",
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Integration Test"
            }), factory);

            var message = NotificationRequestModel.Email("*****@*****.**", "subject", "message");

            message.AddToken("-name-", "John Doe");
            message.AddToken("-city-", "Denver");
            message.AddToken("subject", "SendGrid Subject");

            await sender.SendEmailAsync(message, NotificationType.ResetPassword);
        }
예제 #2
0
        public void SendGridFactoryShouldSetTokensAndTemplateId()
        {
            var factory = new SendGridMailFactory(new OptionsWrapper <MailOptions>(new MailOptions()
            {
                FromAddress     = "*****@*****.**",
                FromDisplayName = "Test",
                Templates       = new List <TemplateItem>()
                {
                    new TemplateItem()
                    {
                        Id   = "123",
                        Type = NotificationType.ResetPassword
                    }
                }
            }));
            var message = NotificationRequestModel.Email("*****@*****.**", "subject", "message");

            message.AddToken("token", "test");

            var result = factory.CreateMessage(NotificationType.ResetPassword, message);

            result.Personalizations[0].Substitutions.Count.Should().BeGreaterThan(0);
            result.TemplateId.Should().NotBeNullOrEmpty();
        }