case 4310
This commit is contained in:
@@ -243,8 +243,18 @@ namespace AyaNova.Api.Controllers
|
||||
if (!ModelState.IsValid)
|
||||
return BadRequest(new ApiErrorResponse(ModelState));
|
||||
|
||||
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, null, "Email notifications are set to OFF at server, unable to send 'on request' type SMTP notification"));
|
||||
|
||||
//validate
|
||||
//for now I'm allowing any authenticated user to call this route intentionally as the use case is for our own internal messaging from the Customer form only or for API users who want to send
|
||||
//email when rendering a report (case 4310).
|
||||
|
||||
//validate incoming data
|
||||
if (string.IsNullOrWhiteSpace(notifyDirectSMTP.Subject))
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, "Subject", "Subject field is required"));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(notifyDirectSMTP.TextBody) && string.IsNullOrWhiteSpace(notifyDirectSMTP.HTMLBody))
|
||||
return BadRequest(new ApiErrorResponse(ApiErrorCode.VALIDATION_MISSING_PROPERTY, null, "TextBody or HTMLBody field is required"));
|
||||
|
||||
if (string.IsNullOrWhiteSpace(notifyDirectSMTP.ToAddress))
|
||||
{
|
||||
@@ -277,19 +287,7 @@ namespace AyaNova.Api.Controllers
|
||||
IMailer m = AyaNova.Util.ServiceProviderProvider.Mailer;
|
||||
try
|
||||
{
|
||||
if (!ServerGlobalOpsSettingsCache.Notify.SmtpDeliveryActive)
|
||||
{
|
||||
await NotifyEventHelper.AddGeneralNotifyEvent(NotifyEventType.GeneralNotification,
|
||||
$"Email notifications are set to OFF at server, unable to send 'on request' type SMTP notification subject:{notifyDirectSMTP.Subject}",
|
||||
"Error",
|
||||
null,
|
||||
UserId);
|
||||
log.LogInformation($"** WARNING: SMTP notification is currently set to Active=False; unable to send 'on request' type SMTP notification subject:{notifyDirectSMTP.Subject} **");
|
||||
|
||||
}
|
||||
else
|
||||
await m.SendEmailAsync(notifyDirectSMTP.ToAddress, "Test from Notification system", "This is a test to confirm notification system is working", ServerGlobalOpsSettingsCache.Notify);
|
||||
|
||||
await m.SendEmailAsync(notifyDirectSMTP.ToAddress, "Test from Notification system", "This is a test to confirm notification system is working", ServerGlobalOpsSettingsCache.Notify);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace AyaNova.Util
|
||||
{
|
||||
public interface IMailer
|
||||
{
|
||||
Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDF = null, string forceFileName = null);
|
||||
Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDF = null, string forceFileName = null, string htmlBody = null);
|
||||
}
|
||||
|
||||
public class Mailer : IMailer
|
||||
@@ -19,7 +19,7 @@ namespace AyaNova.Util
|
||||
|
||||
}
|
||||
|
||||
public async Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDFPath = null, string forceFileName = null)
|
||||
public async Task SendEmailAsync(string email, string subject, string body, AyaNova.Models.GlobalOpsNotificationSettings smtpSettings, string attachPDFPath = null, string forceFileName = null, string htmlBody = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -49,8 +49,18 @@ namespace AyaNova.Util
|
||||
}
|
||||
else
|
||||
{
|
||||
// if (!string.IsNullOrWhiteSpace(body))
|
||||
// message.Body = new TextPart(TextFormat.Plain) { Text = body };
|
||||
|
||||
MimeKit.BodyBuilder builder = new BodyBuilder();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(body))
|
||||
message.Body = new TextPart(TextFormat.Plain) { Text = body };
|
||||
builder.TextBody = body;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(htmlBody))
|
||||
builder.HtmlBody = htmlBody;
|
||||
|
||||
message.Body = builder.ToMessageBody();
|
||||
}
|
||||
|
||||
using (var client = new SmtpClient())
|
||||
|
||||
Reference in New Issue
Block a user