I would like to share a question I have just received by email that may be interesting for other users:
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]
Hi,My answer here:
i wish to filter incoming messages based the massage's sending time. It is possible?
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]