Ejemplo n.º 1
0
        private async Task SendEmail(EmailViewModel viewModel)
        {
            var tokens = GetTokens(viewModel);

            await _notificationApi.SendEmail(new Email()
            {
                RecipientsAddress = viewModel.EmailAddress,
                TemplateId        = viewModel.TemplateId.ToString(),
                Tokens            = tokens,
                SystemId          = "ApplyService",
                ReplyToAddress    = "*****@*****.**",
                Subject           = viewModel.Subject
            });
        }
        private static void SendEmail()
        {
            //var apiBaseUrl = "https://at-notifications.apprenticeships.sfa.bis.gov.uk/";
            var apiBaseUrl = Configuration.NotificationsApiClientConfiguration.ApiBaseUrl;

            //var token = "<your token>";
            var token = Configuration.NotificationsApiClientConfiguration.ClientToken;

            var config = new NotificationsApiClientConfiguration
            {
                ApiBaseUrl  = apiBaseUrl,
                ClientToken = token
            };

            IGenerateBearerToken jwtToken = new JwtBearerTokenGenerator(config);

            var httpClient = new HttpClientBuilder()
                             .WithBearerAuthorisationHeader(jwtToken)
                             .WithDefaultHeaders()
                             .Build();

            var apiClient = new NotificationsApi(httpClient, config);

            var recipients = Configuration.DefaultEmailAddress;
            var sender     = Configuration.DefaultEmailSenderAddress;
            var replyTo    = Configuration.DefaultEmailReplyToAddress;

            var customFields = new Dictionary <string, string>
            {
                { "UserEmailAddress", sender },
                { "UserFullName", "Test User" },
                { "UserEnquiry", "I have a question" },
                { "UserEnquiryDetails", "Wanted to have different appSettings for debug and release when building your app ? " }
            };

            var c = new Email
            {
                Tokens            = customFields,
                RecipientsAddress = recipients,
                ReplyToAddress    = replyTo,
                SystemId          = "xyz",
                TemplateId        = "VacancyService_CandidateContactUsMessage",
                Subject           = "hello"
            };

            apiClient.SendEmail(c).Wait();
        }
Ejemplo n.º 3
0
        private async Task SendEmail(EmailViewModel viewModel)
        {
            _logger.LogInformation($"CreateInvitationHandler : SendEmail : ViewModel: {JsonConvert.SerializeObject(viewModel)}");

            var tokens = GetTokens(viewModel);

            try
            {
                await _notificationApi.SendEmail(new Email()
                {
                    RecipientsAddress = viewModel.EmailAddress,
                    TemplateId        = viewModel.TemplateId.ToString(),
                    Tokens            = tokens,
                    SystemId          = "ApplyService",
                    ReplyToAddress    = "*****@*****.**",
                    Subject           = viewModel.Subject
                });
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, $"Error sending email template ({viewModel.TemplateId}) to: '{viewModel.EmailAddress}'");
                throw;
            }
        }