AspEmail Manual Chapter 8: Message Queuing. Part II

Contents

8.1 Logging

EmailAgent logs all failed sends in the ascii text file EmailAgent.log located under the \Log sub-folder of the main message queue folder. It can optionally log successful sends as well.

A typical failure entry may look as follows:

2003/02/20 17:51:31.793 File:20030220-17512416-980-0 From:<user@aspupload.com> To:<info@persits.com> FAILURE: SMTP connect to servername:25

A success entry may look as follows:

2003/02/20 17:55:03.578 File:20030220-17545845-980-0 From:<user@aspupload.com> To:<info@persits.com> SUCCESS: Sending to imail.innerhost.com [imail.hosting.innerhost.com]: 250 Message queued

All entries contain a timestamp, the name of a file containing the message, the From: and To: information, and a reason for failure (or a success notification from the SMTP server).

Whether to log all messages or errors only can be set on the Log tab:

If you opt to log error messages only, you may also choose to log POP3 retrievals. These types of log entries are useful for bounced message handling described below.

8.2 Programmatic Access to the Log

The AspEmail setup includes a component, EmailLogger.dll, which provides programmatic access to the log entries.

The following code snippet opens the current log file and displays all entries in it:

Set Logger = Server.CreateObject("Persits.MailLogger")
Logger.Open ' open default log

For Each Record in Logger.Records
   Response.Write Record.Text & "<BR>"
Next

Logger.Close

The Open method accepts an optional argument specifying the location of the log file. If nothing is specified, the default log file is opened.

The Records property returns the collection of LogEntry objects representing individual log entries. The LogEntry object supports the following properties:

Text - returns the entire log entry text.

FileName - returns the filename of the message file responsible for this entry.

DateTime - returns timestamp information for this log entry.

Status - returns the strings "SUCCESS", "FAILURE", "ERROR", "SYSTEM" or "RECEIVED" for a successful send, failed send (non-fatal, message will be resent), failed send (fatal, message will not be resent), system error, or received email, respectively. Mail receiving is covered later in this chapter.

Recipient - returns the recipient address. This property is particularly useful for bounced mail handling purposes (covered below).

8.3 Bounced Mail Handling

Every time an email message is sent by a company to a large number of recipients (e.g. a newsletter to subscribers), the sender almost always receives a certain amount of "bounced" mail as addresses tend to become obsolete over time. Therefore, any database of email addresses needs to be cleaned up periodically to get rid of addresses that are no longer valid. AspEmail 5.0 offers a set of features enabling you to handle bounced mail efficiently.

You must take the following steps to set up a bounced-mail handling framework using AspEmail 5.0:

Step 1. Set up a "sink" mail account where all bounced messages would go. Let's call it bounced@yourcompany.com. You may also use an existing mail account.

Step 2. In your mail-sending script, set the property Mail.MailFrom to the "sink" address:

Mail.MailFrom = "bounced@yourcompany.com"

This ensures that all bounced messages will come to this address, and not the one specified via Mail.From.

Step 3. Configure EmailAgent's POP3 tab:

The option "Disable APOP" should be used if your POP3 server does not support APOP authentication, which is rare.

Step 4. During and after a batch send, EmailAgent will retrieve bounced messages from the "sink" account and place them into the \Incoming subfolder underneath the main message queue folder. At the same time, an entry will be added to the log, which may look as follows:

2003/02/28 13:20:13.637 SUCCESS: Received message #1 C:\Queue\Incoming\2816cd831.eam-rcv (11297 bytes) Original-Recipient=username@somecompany.com

You can now retrieve and process all bounced mail addresses using the EmailLogger component, as follows:

Set Logger = Server.CreateObject("Persits.MailLogger")
Logger.Open ' open default log

For Each Record in Logger.Records
   If Record.Status = "RECEIVED" and Record.Recipient <> "" Then
      ' Do something with Record.Recipient
   End if
Next

Logger.Close

You can replace the "Do something" line with ADO-based script that removes the Record.Recipient value from your address database.

Note that Record.Recipient can sometimes be empty as it is not always possible to extract a recipient address from a bounced message, therefore you must test this property for an empty value.

IMPORTANT: You must enable the option "Log all messages" or check the box "Log POP3 Retrievals" on the Log tab for the bounced-message feature to work.