Chapter 7. Message Queuing. Part I
7.1 Why Use Message Queuing?
7.2 Configuring EmailAgent
7.3 Deferred Processing
7.4 EmailAgent vs. EmailAgent.NET
When the method Mail.Send is called, AspEmail opens a session
with the SMTP server and sends message information to it for
further processing and delivery. Depending on the message size, an SMTP session
may take a long time to complete. Sending messages to
hundreds or thousands of recipients may put a heavy load on
IIS for an extended period of time and
affect the overall Web server performance.
AspEmail 5.0 offers the flag Mail.Queue which, if set to True,
instructs the Send method to place a message in a queue
and return immediately, without opening an SMTP session. Your message-sending
ASP script no longer has to wait until a message is sent, which means
a better client-response time and less load on IIS.
AspEmail is shipped with EmailAgent.exe, a Windows
service running in the background, which polls the message queue
and sends out queued messages. EmailAgent 5.0 is capable of opening up
to 64 simultaneous SMTP sessions for quicker processing.
The old method Mail.SendToQueue is still supported for backwards
compatibility, but it is recommended that the sequence
Mail.Queue = True
be used instead (where SendXXX is one of the following methods: Send, SendEncrypted, SendSigned,
and SendSignedAndEncrypted). Unlike older versions, AspEmail 5.0 can queue
encrypted and/or signed messages as well.
AspEmail creates message files in the plain ASCII format, so that they can
be easily viewed and modified by hand, if necessary. A typical file name
looks like this: 20030408-16195159-23c-0.eam-new. Once a message
file is placed in the queue, its name can be retrieved
via the read-only property Mail.QueueFileName.
EmailAgent installation instructions can be found in Chapter 1.
Once EmailAgent has been installed on your system, the EmailAgent button should appear in Control Panels,
Double-click on the EmailAgent button. The EmailAgent Control Panel applet will
come on which enables you to configure, launch and shut down EmailAgent.
It also allows you to monitor thread status and view logs.
The General tab displays the current status of the EmailAgent service as a whole
(left pane) and each individual thread (right pane). The Go button
launches the service, Stop stops the service, and Queue displays the content
of the message queue folder.
The Configuration tab contains basic parameters including the message
queue folder, the number of simultaneous SMTP sessions, and others.
Message Queue Path
This parameter specifies a folder on the server's hard drive
where queued messages are placed when the Mail.Queue property is set to True and the
method Mail.Send is called. Any physical folder can be used for queued messages. EmailAgent will automatically
create 4 subfolders underneath the specified folder: \Sent, \Failed, \Incoming, and \Log.
Successfully sent messages are copied from the main queue folder to the \Sent folder,
and failed messages to the \Failed folder. Incoming message are saved in the \Incoming folder.
The \Log folder contains the log file.
This number must be between 1 and 64 and defaults to 16. It specifies
the number of SMTP sessions EmailAgent opens simultaneously with an SMTP server to send out queued
Tip: While it may be tempting to use all 64 threads,
consider the following: if your SMTP server
is configured to limit the total number of simultaneous sessions to, say, 20,
all extra sessions will be dropped, and the corresponding messages returned to the queue for resending.
This will actually slow your system down. Ask your system administrator
how many simultaneous sessions your SMTP server allows, and set this parameter
Poll message queue every ... seconds
This parameter specifies when to poll the message queue again if it is currently empty.
Repeat sending after ... minutes
When a non-fatal error occurs during an SMTP session, a message is left
in the main queue for EmailAgent to try and resend it. This parameter specifies how
soon EmailAgent should attempt to send this message again.
Cancel sending after ... hours
If a message generates a non-fatal error, EmailAgent attempts to send it
repeatedly for the specified number of hours. If unsuccessful, it copies the
message to the \Failed folder. Once a message is in the \Failed folder,
no further attempts are made to send it.
Do not move sent messages to the \Sent folder
By default, all successfully sent messages are moved to the \Sent folder. If this
option is checked, sent messages are simply deleted from the queue.
The SMTP tab configures SMTP parameters.
Relay through ... Host/Relay through DNS
Starting with AspEmail 5.0, the Mail.Host property is optional.
If no Host is specified when generating queued mail,
EmailAgent will use the host address specified in Relay through .... Host,
or attempt to use the recipient's own SMTP server, if Relay through DNS
The address of the recipient's SMTP server is derived from the
recipient's email address by looking up DNS records. DNS relaying is slower
but it does not require the sender to have his/her own SMTP relay server.
If necessary, specify authentication parameters to be used with the SMTP server.
The POP3 and Log tabs will be described in the next chapter.
With AspEmail 5.0, you can specify the exact date and time when you
want a message to be delivered via the Timestamp property, as follows:
Mail.Timestamp = CDate("Feb 28, 2003 10:15:00 PM")
Mail.Queue = True
If you wish a message to be delivered in, say, 5 hours, the following code may be used:
Mail.Timestamp = Now() + 5/24 ' dates are measured in days, so 1/24 is one hour
While EmailAgent will continue to be supported, we recommend that EmailAgent.NET,
a more advanced version of EmailAgent released on Nov 1, 2011, be used instead.
EmailAgent.NET is shipped with AspEmail.NET but can be used with AspEmail as well.
It does not require a separate license.
Compared to EmailAgent, EmailAgent.NET supports multiple queues, up to 256 simultaneous sessions
per queue, TLS and, improved logging.
For more information about EmailAgent.NET, please see Chapter 4
of the AspEmail.NET User Manual.