private static void RegisterDasNotifications(IServiceCollection services, IConfiguration configuration) { var notificationsConfig = new NotificationsApiClientConfiguration(); configuration.GetSection(nameof(NotificationsApiClientConfiguration)).Bind(notificationsConfig); var jwtToken = new JwtBearerTokenGenerator(notificationsConfig); var httpClient = new HttpClientBuilder() .WithBearerAuthorisationHeader(jwtToken) .WithDefaultHeaders() .Build(); services.AddTransient <INotificationsApi>(sp => new NotificationsApi(httpClient, notificationsConfig)); }
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(); }