using KB.SpeeDing.Common;
using KB.SpeeDing.Common.Contracts;
using KB.SpeeDing.Common.Notification;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
namespace KB.SpeeDing.Notification.Services
public class SmtpNotificationDestinationService : ICommonConnectedService<NotificationMessage>
protected ILogger Logger { get; set; }
private SmtpClient client { get; set; }
private IConfiguration Configuration { get; set; }
public SmtpNotificationDestinationService(ILogger<SmtpNotificationDestinationService> logger, SmtpClient client, IConfiguration Configuration)
this.Configuration = Configuration;
protected virtual string GetName()
return "Smtp Notification";
public async Task<bool> ProcessBegin(NotificationMessage message, CancellationToken cancellationToken)
await Task.Run(() => { }, cancellationToken);
throw new System.NotImplementedException();
public async Task<bool> Process(NotificationMessage message, CancellationToken cancellationToken)
Logger.LogInformation(message.DestinationHeader, $"{GetName()} notification service. Only logging. Message: {message?.SourceData?.Subject}, type: {message?.SourceData?.NotificationType}");
await Task.Run(() => { }, cancellationToken);
private void SendEmail(NotificationData Data)
var message = new MimeMessage();
message.From.Add(new MailboxAddress("Joey Tribbiani", "joey@friends.com"));
message.To.Add(new MailboxAddress("Mrs. Chanandler Bong", "chandler@friends.com"));
message.Subject = "How you doin'?";
message.Body = new TextPart("plain")
Text = @"Hey Chandler,..."
using (var client = new SmtpClient())
client.Connect("smtp.friends.com", 587, false);
client.Authenticate("joey", "password");
public async Task<bool> ProcessEnd(NotificationMessage message, CancellationToken cancellationToken)
await Task.Run(() => { }, cancellationToken);
throw new System.NotImplementedException();
public class NotificationMessage: CommonProcessMessage<NotificationData, DirectResult, ConsumeResult<string, byte[]>>
public enum Classification { C0, C1, C2, C3};
public class NotificationData
public string NotificationType { get; set; }
public string Subject { get; set; }
public string Message { get; set; }
public Classification Classification {get; set;} = Classification.C1;
public string Source { get; set; }
public string DestinationType { get; set; }
public CommunicationHeader CommunicationHeader { get; set; }