Page 1 of 1

Autorespond to email other than sender's?

PostPosted: Thu Jan 11th, 2007 7:09pm
by leo
:roll: I would like Mailtraq to autorespond to email address other than sender's? Basically I want to receive email notifications on my cell phone (e.g. 123456890@mobilphoneco.com) or in another external email when there is new mail in my mailbox? Would be nice to include only "from" and "subject" as part of information.

I was also wondering if it is possible to autorespond only when message is from particular sender or contains particular subject. Please help.

Re: Autorespond to email other than sender's?

PostPosted: Thu Jan 18th, 2007 12:40pm
by Martin Clayton
Hi,
leo wrote:I would like Mailtraq to autorespond to email address other than sender's? Basically I want to receive email notifications on my cell phone (e.g. 123456890@mobilphoneco.com) or in another external email when there is new mail in my mailbox? Would be nice to include only "from" and "subject" as part of information.

You could test the template below. To set-up for a mailslot called "test", use the Templates dialog (at Options, Scripts and Templates...) to Subclass the autoresponder, then Edit the 'test' file replacing all content with:

Code: Select all
<@LANGUAGE=JavaScript@>
<%
  // autoresponder template (autoresponder~{mailslot-name}.tpl)
  // Martin Clayton: Jan 07
  // - Send email notification on new mail
  // - Optionally, only notify when headers match contents
  //   specified in a text file

  // Custom vars --------------------------

  // output message properties
  var OutputMsgAddress = "123456890@mobilphoneco.com";
  var OutputMsgSubject = "New mail notification";
  var OutputMsgFrom = "postmaster@my-domain.com";
 
  // Only alert when 1+ header matches entries in config file?
  var NotifyWhenHeadersMatch = true;
 
  // File for header matches
  var HdrMatchFile = "auto-notify~test.txt";

  // Must be in the database folder, format:

  // [From]
  // pm@gov.uk
  // Farraday, Jack
  //
  // [Subject]
  // Auto notification test
  // Meeting
  //
  // [To]
  // abuse@

  // --------------------------------------

  var InputHdrFrom = Request.GetHeader("From");
  var InputHdrSubject = Request.GetHeader("Subject");

  var notify = true;

  if(NotifyWhenHeadersMatch) {

    notify = false;

    // locate header file
    var objShell = new ActiveXObject("WScript.Shell");
    var sys_db = objShell.RegRead("HKLM\\Software\\Fastraq\\Mailtraq\\DatabasePath");
    var HdrMatchFilePath = sys_db + "\\database\\" + HdrMatchFile;

    // read header file, test headers
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    if(fso.FileExists(HdrMatchFilePath)) {
      var f = fso.GetFile(HdrMatchFilePath);
      var ForReading = 1, line = "";
      var HeaderToTest = "", InputHeaderValue = "";
      var ts = f.OpenAsTextStream(ForReading);
      while(!ts.AtEndOfStream && !notify) {
        line = ts.ReadLine();
        if(/^\[.*\]$/.test(line)) {
           HeaderToTest = line.replace(/\[(.*)\]/, "$1");
           InputHeaderValue = Request.GetHeader(HeaderToTest);
        } else {
          if(InputHeaderValue != "" && line != "") {
            var re = new RegExp(line, "igm");
            notify = re.test(InputHeaderValue);
          }
        } 
      }
      ts.Close();
    }
  }

  if(notify) {
 
    var OutputMsgHdrs = "To: " + OutputMsgAddress + "\r\n" +
                        "Subject: " + OutputMsgSubject + "\r\n" +
                        "From: " + OutputMsgFrom + "\r\n" +
                        "Precedence: bulk" + "\r\n" +
                        "X-POST-MessageClass: 9; Autoresponder" + "\r\n";

    var OutputMsgBody = "Message received:" + "\r\n" +
                        "From: " + InputHdrFrom + "\r\n" +
                        "Subject: " + InputHdrSubject;

    Server.MessageSend("", OutputMsgAddress, OutputMsgHdrs, OutputMsgBody, "", "");

  }

  // Divert Mtq's native autoresponder template response
  Response.Recipients.Set(0, "dev-null");
  Response.SetHeader("X-MTQ-Route", "Dev/null");

%>

Mailtraq's native template response can be expired in a dev-null mailslot or you could use Automated Scripting to fire a blank script (say, dev-null.mtq) - Trigger: Mail Routing, Filter: X-MTQ-Route = dev/null & use the handoff property to drop the message.

Just ask for clarification if there are any glitches or any of this sounds crazy. ;-)

Cheers, Martin