private static void Handle(SimpleEmailEvent sesEvent)
 {
     foreach (var record in sesEvent.Records)
     {
         var sesRecord = record.Ses;
         Console.WriteLine($"[{record.EventSource} {sesRecord.Mail.Timestamp}] Subject = {sesRecord.Mail.CommonHeaders.Subject}");
     }
 }
Exemplo n.º 2
0
        public void TestToSESPassFunction()
        {
            var sesEventString        = File.ReadAllText("sesEventPass.json");
            SimpleEmailEvent sesEvent = JsonConvert.DeserializeObject <SimpleEmailEvent>(sesEventString);

            var function = new Function();
            var context  = new TestLambdaContext();
            var result   = function.FunctionHandler(sesEvent, context);

            Assert.Null(result);
        }
Exemplo n.º 3
0
        public void TestToSESFailFunction()
        {
            var sesEventString        = File.ReadAllText("sesEventFail.json");
            SimpleEmailEvent sesEvent = JsonConvert.DeserializeObject <SimpleEmailEvent>(sesEventString);
            const string     stopRule = "{ disposition = STOP_RULE_SET }";

            var function = new Function();
            var context  = new TestLambdaContext();
            var result   = function.FunctionHandler(sesEvent, context);

            Assert.Equal(stopRule, result.ToString());
        }
Exemplo n.º 4
0
        /// <summary>
        /// Parse SES Event to check for SPAM and stop SES Rule Set if detected
        /// </summary>
        /// <param name="evt"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public Object FunctionHandler(SimpleEmailEvent evt, ILambdaContext context)
        {
            var sesNotification = evt.Records[0].Ses;

            Console.WriteLine(sesNotification.Mail.Source);

            // Check if any spam check failed
            if (sesNotification.Receipt.SPFVerdict.Status == "FAIL" ||
                sesNotification.Receipt.DKIMVerdict.Status == "FAIL" ||
                sesNotification.Receipt.SpamVerdict.Status == "FAIL" ||
                sesNotification.Receipt.VirusVerdict.Status == "FAIL")
            {
                Console.WriteLine("Dropping spam");
                // Stop processing rule set, dropping message
                return(new { disposition = "STOP_RULE_SET" });
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 5
0
 public string FunctionHandler(SimpleEmailEvent inputData)
 {
     return(inputData.Records.First().EventSource);
 }