Ejemplo n.º 1
0
 void Enqueue(MimeMessageContainer container)
 {
     if (_emailNotificationsEnabled)
     {
         Consumer.Enqueue(container);
     }
     else
     {
         // TODO: store the e-mail?
     }
 }
        async Task <bool> LogEmailFailure(string descr, MimeMessageContainer container, bool save = false)
        {
            try
            {
                var msg   = container.Message;
                var msgId = msg.MessageId;

                if (!await LogContains(msgId))
                {
                    var obj = new OutgoingMessage
                    {
                        MessageId = msgId,
                        Subject   = msg.Subject ?? string.Empty,
                        Body      = ((TextPart)msg.Body).Text ?? string.Empty,
                        From      = string.Join(",", msg.From.Select(addr => addr.ToString())),
                        To        = string.Join(",", msg.To.Select(addr => addr.ToString())),
                    };
                    _sysRepo.Add(new SysEventLog
                    {
                        MessageId   = msgId,
                        UserId      = container.UserId,
                        Description = descr,
                        EventType   = SysEventType.EmailSendFailed.ToString(),
                        ObjectState = SerializeObject(obj),
                    });

                    if (save)
                    {
                        await _sysRepo.SaveChangesAsync(CancellationTokenSource.Token);
                    }

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, $"Error in {nameof(LogEmailFailure)} while adding e-mail log.");
            }
            return(false);
        }
 bool FindContainer(string messageId, out MimeMessageContainer container)
 {
     container = _workingSet.FirstOrDefault(c => c.MessageId == messageId);
     return(container != null);
 }