/// <inheritdoc />
        public override Task <SmtpResponse> SaveAsync(ISessionContext context, IMessageTransaction transaction, CancellationToken cancellationToken)
        {
            var textMessage = (ITextMessage)transaction.Message;

            var message = MimeMessage.Load(textMessage.Content);

            foreach (var sender in message.From)
            {
                foreach (var recipient in message.To)
                {
                    if (!(sender is MailboxAddress senderEmail) || !(recipient is MailboxAddress recipientEmail))
                    {
                        continue;
                    }

                    try
                    {
                        var acmeMessage = MimeKitConverter.ConvertToMessage(senderEmail, recipientEmail, message);
                        Log.Info($"INCOMING FROM {senderEmail.Address} TO {recipientEmail.Address} : {message.Subject}");

                        this.MessageReceived?.Invoke(this, acmeMessage);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }

            return(Task.FromResult(SmtpResponse.Ok));
        }
Пример #2
0
        private void ProcessMails(MimeMessage message)
        {
            message.ThrowIfNull(nameof(message));

            foreach (var sender in message.From)
            {
                foreach (var recipient in message.To)
                {
                    if (!(sender is MailboxAddress senderEmail) || !(recipient is MailboxAddress recipientEmail))
                    {
                        continue;
                    }

                    var acmeMessage = MimeKitConverter.ConvertToMessage(senderEmail, recipientEmail, message);
                    this.RaiseMessageReceived(acmeMessage);
                }
            }
        }