email parsing automation

Email Parser

Extract data from emails and automate your workflow

The forum is now read only. Please, go to the the main Email Parser website if you need help.
Need help configuring the program? Have any questions regarding its use?
I would like to share a question I have just received by email that may be interesting for other users:
Hi,
i wish to filter incoming messages based the massage's sending time. It is possible?
My answer here:

With the usual email filter settings you can filter incoming emails based on the date only (as you probably have seen). If you want to filter based on the time you would need to create a script-based email filter like this:

[syntax=csharp]
using System;
using System.Net.Mail;
using EmailAndParser.ScriptingInterface;

public class MyFilter : ScriptBasedEmailFilter
{
public override bool FilterEmail(MailMessage msg)
{
DateTime date_time_object;

if(!DateTime.TryParse(msg.Headers["Date"], out date_time_object))
{
Print("Cannot retrieve message date and time");
return(false);
}

Print("The email has been sent at "+date_time_object.Hour.ToString()+":"+date_time_object.Minute.ToString());

// Only accepts emails from 17:00 to 23:00
if(date_time_object.Hour >= 17 && date_time_object.Hour <= 23)
return(true); // accepted email
else
return(false); // rejected email
}
}
[/syntax]