Search Criteria

Search Criteria

Developing the search criteria for email messages is part art and part science. The most important part of the process is determining the timestamp that was assigned to the message. In most cases, this is the time that the message was received, which will always be different than the timestamp you will obtain from the sending service. Furthermore, many machines are not connected to a standard time service, which means that their clocks are unlikely to be synchronized with yours. There are also decisions that were made about the time zones assigned to the server than affect the timestamp. As a result, the timestamp given to you by the sending service is the “best estimate” for a starting time for the search for the message. There have been cases where the timestamp on the email was three hours earlier than the sender expected because the recipient server was associated with Pacific Standard Time, and the sender’s server was associated with Eastern Standard Time. This needs to be considered when the “best estimate” time fails to produce a search result.

One way to overcome these time differences is to iterate through the results the server has. You can do this starting with either the first message in a list or the last. The method is as follows:

To iterate forward in time from the first message to the last:

  1. Set the “fromAddress”
  2. Set the “startDate” parameter to the earliest possible time, which is approximately “1/1/1900”.
  3. Set the “matchFirst” flag to “true”
  4. Set the “searchByDate” flag to “true”

Now send the request. The EmailReach web service will return the first message that it received from this “fromAddress”. To obtain every other message received, change the search parameters as follows:

  1. Take the “Date Sent” timestamp from the email that the web service found, and add one minute to it.
  2. set the “startDate” parameter to this value.

Send the request again. This will return the second email that the web service has for this “fromAddress”. Repeat this process of updating the “startDate” with the timestamp from the last email that you received from the web service and you will eventually have a complete list of all of the test messages that the web service has received.

Your web site can either search this list for interesting messages, or you can display it to the user and let them pick a message. Either way, when you want to retrieve one of the listed messages, you can set the “startDate” and the “endDate” parameters to the timestamp on the message and be assured you will get the message you expect.