//Used by API public async Task <ApiResponse> SendTestEmail(EmailDto parameters) { EmailMessageDto email = _emailFactory.BuildTestEmail(parameters.ToName); email.ToAddresses.Add(new EmailAddressDto(parameters.ToName, parameters.ToAddress)); return(parameters.Queued ? await QueueEmail(email, EmailType.Test) : await SendEmail(email)); }
//Used from API public async Task <ApiResponse> Send(EmailDto parameters) { EmailMessageDto email = null; //This forces all emails from the API to use the Test template to prevent spam parameters.TemplateName = "Test"; //Send a Template email or a custom one since it is hardcoded to Test template it will not do a custom email. if (!string.IsNullOrEmpty(parameters.TemplateName)) { switch (parameters.TemplateName) { case "Test": email = _emailFactory.BuildTestEmail(); email.ToAddresses.Add(new EmailAddressDto(parameters.ToName, parameters.ToAddress)); break; default: break; } } else { email = _emailFactory.BuildTestEmail(); email.Subject = parameters.Subject; email.Body = parameters.Body; } //Add a new From Address if you so choose, default is set in appsettings.json //email.FromAddresses.Add(new EmailAddress("New From Name", "*****@*****.**")); _logger.LogInformation("Test Email: {0}", email.Subject); try { await SendEmailAsync(email); return(new ApiResponse(Status200OK, "Email Successfuly Sent")); } catch (Exception ex) { return(new ApiResponse(Status500InternalServerError, ex.Message)); } }
//Used by API public async Task <ApiResponse> SendTestEmail(EmailDto parameters) { EmailMessageDto email = _emailFactory.BuildTestEmail(parameters.ToName); email.ToAddresses.Add(new EmailAddressDto(parameters.ToName, parameters.ToAddress)); email.Subject = $"Test email from {_emailFactory.BaseUrl}"; email.Body = "Test email completed."; try { return(await SendEmailAsync(email)); } catch (Exception ex) { return(new ApiResponse(Status500InternalServerError, ex.Message)); } }