public SesEvent ParseRecord(SNSEvent.SNSRecord record, ILambdaContext context) { context.Logger.LogLine($"Parsing record for {record.Sns.Type} from source {record.EventSource}."); var notification = JsonSerializer.Deserialize <SesNotification>(record.Sns.Message, new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase, DictionaryKeyPolicy = JsonNamingPolicy.CamelCase }); var evt = new SesEvent { EventType = notification.NotificationType, Timestamp = notification.Mail.Timestamp, // MessageId = notification.Mail. Source = notification.Mail.Source, SourceArn = notification.Mail.SourceArn, SourceIp = notification.Mail.SourceIp, SendingAccountId = notification.Mail.SendingAccountId, FromAddress = notification.Mail.CommonHeaders.From.First(), Subject = notification.Mail.CommonHeaders.Subject, MessageDate = notification.Mail.CommonHeaders.Date, // Recipients = notification.Mail.CommonHeaders.To }; if (notification.Mail.CommonHeaders.To?.Any() ?? false) { foreach (var toAddr in notification.Mail.CommonHeaders.To.Where(x => !string.IsNullOrEmpty(x))) { if (toAddr.Contains(",")) { evt.Recipients.AddRange(toAddr.Split(',', StringSplitOptions.RemoveEmptyEntries)); } else { evt.Recipients.Add(toAddr); } } } switch (notification.NotificationType) { case "Bounce" when notification.Bounce != null: evt.SubType = $"{notification.Bounce.BounceType} - {notification.Bounce.BounceSubType}"; evt.FeedbackId = notification.Bounce.FeedbackId; break; } return(evt); }
private async Task SaveEventAsync(SesEvent evt) { await _dbContext.SaveAsync(evt); }