Date-Controlled E-Mail Reply


In addition to the tutorial on sending automatic reply emails, there is the option of giving these reply emails additional date or time-controlled parameters.

This can be particularly useful during periods of limited business activity, e.g. during vacation periods as a type of out-of-office message.

Please make the appropriate settings in the arrival action of the mailbox in question.
The following script enables you to specify the desired time interval in which a defined reply email should be sent when a request is received:

    function isHolidays()
    {
       var startDate = new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm").parse("2016.12.23 13:00");
       var endDate = new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm").parse("2017.01.03 00:00");
       var now = new java.util.Date();
       return now.after(startDate) && now.before(endDate);
    }
if (isHolidays())
 {
// desired action...
 }

This line...

var startDate = new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm").parse("2016.12.23 13:00");

sets the start date and this...

var endDate = new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm").parse("2017.01.03 00:00");

sets the end date of the time interval.

The desired action is now defined, in our case the sending of an automated email (auto-reply).

function isHolidays()
    {
       var startDate = new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm").parse("2016.12.23 13:00");
       var endDate = new java.text.SimpleDateFormat("yyyy.MM.dd HH:mm").parse("2017.01.03 00:00");
       var now = new java.util.Date();
       return now.after(startDate) && now.before(endDate);
    }


if (isHolidays())
 {
var id = task.id;
var email = message.getFrom()[0].getAddress();
                           
var footer = task.source.sourcemailbox.footer;
             
var text = "<html><head></head><body><p>Dear Madam or Sir,<br/><br/>\n";
text += "thanks for your e-mail.<br/><br/>";
text += "Please note your ticket ID: "+id+"<br/><br/>\n";
text += "Kind regards<br/>\n";
text += "Your Service Team<br/></p><br/>\n";
text += "</p><br/>";
text += "\n<br/><br/>"+footer+"</body></html>";

helper.sendmail(
   task.source.sourcemailbox.emailAddress, // sender email address
  "Your request to "
  +task.source.sourcemailbox.emailAddress+" (ID: "+id+")", // subject
  text, // message
  email, // addressee
  null, // cc
  null, // bcc
  "support@yourcompany.de", // reply to
 true // html formatted message
);
 }

.