Distributed James Server — Mailets
This documentation page lists and documents Mailet that can be used within the Distributed James Server MailetContainer in order to write your own mail processing logic with out-of-the-box components.
Supported mailets
AddDeliveredToHeader
This mailet adds the de-facto standard QMail Delivered-To header.
Upon processing by LocalDelivery, a Delivered-To header matching the recipient mail address will be added before storage.
Example
<mailet match="All" class="AddDeliveredToHeader">
AddFooter
Takes the message and attaches a footer message to it. Right now, it only supports simple messages. Needs to have additions to make it support messages with alternate content types or with attachments.
AddSubjectPrefix
Add an prefix (tag) to the subject of a message <br>
Sample Configuration:
<mailet match="RecipientIs=robot@james.apache.org" class="TagMessage"> <subjectPrefix>[robot]</subjectPrefix> </mailet>
AmqpForwardAttribute
This mailet forwards the attributes values to a AMPQ.
It takes 4 parameters:
-
attribute (mandatory): content to be forwarded, expected to be a Map<String, byte[]> where the byte[] content is issued from a MimeBodyPart. It is typically generated from the StripAttachment mailet.
-
uri (mandatory): AMQP URI defining the server where to send the attachment. High availability is supported with a coma separated list of uris, whost and credentials are taken from the first URI specified.
-
exchange (mandatory): name of the AMQP exchange.
-
exchange_type (optional, default to "direct"): type of the exchange. Can be "direct", "fanout", "topic", "headers".
-
routing_key (optional, default to empty string): name of the routing key on this exchange.
This mailet will sent the data attached to the mail as an attribute holding a map.
Bounce
Generates a response to the reverse-path address. Note that this is different than a mail-client’s reply, which would use the Reply-To or From header.
Bounced messages are attached in their entirety (headers and content) and the resulting MIME part type is "message/rfc822".
The reverse-path and the Return-Path header of the response is set to "null" ("<>"), meaning that no reply should be sent.
A sender of the notification message can optionally be specified. If one is not specified, the postmaster’s address will be used.
A notice text can be specified, and in such case will be inserted into the notification inline text.
If the notified message has an "error message" set, it will be inserted into the notification inline text. If the attachError init parameter is set to true, such error message will be attached to the notification message.
Supports the passThrough init parameter (true if missing).
Sample configuration:
<mailet match="All" class="Bounce"> <sender>*an address or postmaster or sender or unaltered, default=postmaster*</sender> <attachError>*true or false, default=false*</attachError> <message>*notice attached to the original message text (optional)*</message> <prefix>*optional subject prefix prepended to the original message*</prefix> <inline>*default=none*</inline> <attachment>*default=message*</attachment> <passThrough>*true or false, default=true*</passThrough> <fakeDomainCheck>*true or false, default=true*</fakeDomainCheck> <debug>*true or false, default=false*</debug> </mailet>
The behaviour of this mailet is equivalent to using Resend with the following configuration:
<mailet match="All" class="Resend"> <sender>*an address or postmaster or sender or unaltered*</sender> <attachError>*true or false*</attachError> <message>**dynamically built**</message> <prefix>*a string*</prefix> <passThrough>true or false</passThrough> <fakeDomainCheck>*true or false*</fakeDomainCheck> <recipients>*sender*</recipients> <reversePath>null</reversePath> <inline>see Resend</inline> <attachment>see Resend</attachment> <isReply>true</isReply> <debug>*true or false*</debug> </mailet>
notice and sendingAddress can be used instead of message and sender; such names are kept for backward compatibility.
ContactExtractor
Collects the sender and the recipients of a message and store them as JSON in a specified message attribute.
Here is the JSON format:
{ "userEmail" : "sender@james.org", "emails" : [ "to@james.org", "cc@james.org" ] }
Sample configuration:
<mailet match="All" class="ContactExtractor"> <attribute>ExtractedContacts</attribute> </mailet>
ConvertTo7Bit
Make sure the message stream is 7bit. Every 8bit part is encoded to quoted-printable or base64 and the message is saved.
DKIMSign
This mailet sign a message using the DKIM protocol If the privateKey is encoded using a password then you can pass the password as privateKeyPassword parameter.
Sample configuration with inlined private key:
<mailet match="All" class="DKIMSign"> <signatureTemplate>v=1; s=selector; d=example.com; h=from:to:received:received; a=rsa-sha256; bh=; b=;</signatureTemplate> <privateKey> -----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDYDaYKXzwVYwqWbLhmuJ66aTAN8wmDR+rfHE8HfnkSOax0oIoT M5zquZrTLo30870YMfYzxwfB6j/Nz3QdwrUD/t0YMYJiUKyWJnCKfZXHJBJ+yfRH r7oW+UW3cVo9CG2bBfIxsInwYe175g9UjyntJpWueqdEIo1c2bhv9Mp66QIDAQAB AoGBAI8XcwnZi0Sq5N89wF+gFNhnREFo3rsJDaCY8iqHdA5DDlnr3abb/yhipw0I /1HlgC6fIG2oexXOXFWl+USgqRt1kTt9jXhVFExg8mNko2UelAwFtsl8CRjVcYQO cedeH/WM/mXjg2wUqqZenBmlKlD6vNb70jFJeVaDJ/7n7j8BAkEA9NkH2D4Zgj/I OAVYccZYH74+VgO0e7VkUjQk9wtJ2j6cGqJ6Pfj0roVIMUWzoBb8YfErR8l6JnVQ bfy83gJeiQJBAOHk3ow7JjAn8XuOyZx24KcTaYWKUkAQfRWYDFFOYQF4KV9xLSEt ycY0kjsdxGKDudWcsATllFzXDCQF6DTNIWECQEA52ePwTjKrVnLTfCLEG4OgHKvl Zud4amthwDyJWoMEH2ChNB2je1N4JLrABOE+hk+OuoKnKAKEjWd8f3Jg/rkCQHj8 mQmogHqYWikgP/FSZl518jV48Tao3iXbqvU9Mo2T6yzYNCCqIoDLFWseNVnCTZ0Q b+IfiEf1UeZVV5o4J+ECQDatNnS3V9qYUKjj/krNRD/U0+7eh8S2ylLqD3RlSn9K tYGRMgAtUXtiOEizBH6bd/orzI9V9sw8yBz+ZqIH25Q= -----END RSA PRIVATE KEY----- </privateKey> </mailet>
Sample configuration with file-provided private key:
<mailet match="All" class="DKIMSign"> <signatureTemplate>v=1; s=selector; d=example.com; h=from:to:received:received; a=rsa-sha256; bh=; b=;</signatureTemplate> <privateKeyFilepath>dkim-signing.pem</privateKeyFilepath> </mailet>
By default the mailet assume that Javamail will convert LF to CRLF when sending so will compute the hash using converted newlines. If you don’t want this behaviour then set forceCRLF attribute to false.
DKIMVerify
This mailet verify a message using the DKIM protocol
Sample configuration:
<mailet match="All" class="DKIMVerify"> </mailet>
By default the mailet assume that Javamail will use LF instead of CRLF so it will verify the hash using converted newlines. If you don’t want this behaviour then set forceCRLF attribute to false.
DSNBounce
Generates a Delivery Status Notification (DSN) Note that this is different than a mail-client’s reply, which would use the Reply-To or From header.
Bounced messages are attached in their entirety (headers and content) and the resulting MIME part type is "message/rfc822".
The reverse-path and the Return-Path header of the response is set to "null" ("<>"), meaning that no reply should be sent.
A sender of the notification message can optionally be specified. If one is not specified, the postmaster’s address will be used.
Supports the <code>passThrough</code> init parameter (true if missing).
Sample configuration:
<mailet match="All" class="DSNBounce"> <sender>*an address or postmaster or sender or unaltered, default=postmaster*</sender> <prefix>*optional subject prefix prepended to the original message*</prefix> <attachment>*message, heads or none, default=message*</attachment> <messageString>*the message sent in the bounce, the first occurrence of the pattern [machine] is replaced with the name of the executing machine, default=Hi. This is the James mail server at [machine] ... *</messageString> <passThrough>*true or false, default=true*</passThrough> <debug>*true or false, default=false*</debug> </mailet>
Expires
Sanitizes or adds an expiration date to a message, in the form of an Expires
header (RFC 4021).
The mailet can force an existing expiration date to be within the bounds
given by minAge
, maxAge
, or both. minAge
specifies the minimum time
the date must lie in the future, while maxAge
specifies a maximum.
If a message has no expiration date, the mailet can add one according to
the optional defaultAge
parameter.
All parameter values should be expressed in the following format: Nunit
.
N
should be positive. unit
could be either in the short form
(h
, d
, w
, y
etc.), or in the long form (hours
, days`, weeks
,
months
, years
). The default unit is days
.
Sample configuration:
<mailet match="All" class="Expires"> <minAge>12h</minAge> <defaultAge>7d</defaultAge> <maxAge>8w</maxAge> </mailet>
By itself the Expires
header is informational only. But some variants of James
will let you delete expired messages through the
WebAdmin interface:
curl -XDELETE http://ip:port/messages?byExpiresHeader
ExtractMDNOriginalJMAPMessageId
This mailet handles MDN messages and define a header X-JAMES-MDN-JMAP-MESSAGE-ID referencing the original message (by its Jmap Id) asking for the recipient to send an MDN.
Forward
Replaces incoming recipients with those specified, and resends the message unaltered.
Can be totally replaced by an equivalent usage of {@link Resend} (see below), simply replacing <forwardto> with <recipients>.
Sample configuration:
<mailet match="All" class="Forward"> <forwardTo>*comma delimited list of email addresses*</forwardTo> <passThrough>*true or false, default=false*</passThrough> <fakeDomainCheck>*true or false, default=true*</fakeDomainCheck> <debug>*true or false, default=false*</debug> </mailet>
The behaviour of this mailet is equivalent to using Resend with the following configuration:
<mailet match="All" class="Resend"> <forwardTo>comma delimited list of email addresses</recipients> <passThrough>true or false</passThrough> <fakeDomainCheck>*true or false*</fakeDomainCheck> <debug>*true or false*</debug> </mailet>
forwardto can be used instead of forwardTo; such name is kept for backward compatibility.
ICalendarParser
This mailet can be combined with the Strip attachment mailet.
The ICS body part byte array is arranged as map then this mailet should look for ICS and parse it with Ical4J then store it as a mail attribute
Configuration: The mailet contains 2 mandatory attributes
<mailet match="All" class="ICalendarParser" > <sourceAttribute>source.attribute.name</sourceAttribute> <!-- The attribute which contains output value of StripAttachment mailet -- > <destAttribute>dest.attribute.name</destAttribute> <!-- The attribute store the map of Calendar -- > </mailet >
ICALToHeader
ICALToHeader takes a Map of filenames to ICAL4J calendars, will pick the first Calendar, and add it to the headers of the e-mail.
The following headers will be added : X_MEETING_UID, X_MEETING_METHOD, X_MEETING_RECURRENCE_ID, X_MEETING_SEQUENCE, X_MEETING_DTSTAMP
The only configuration parameter for this mailet is the attribute the ICAL4J Calendar map should be attached to, named attribute.
Configuration example :
<mailet match=??? class=ICALToHeader> <attribute>icalendars</attribute> </mailet>
ICALToJsonAttribute
ICALToJsonAttribute takes a map of ICAL4J objects attached as attribute, and output the map of corresponding json bytes as an other attribute, with unique String keys.
The JSON contains the following fields :
-
ical : the raw ical string, in UTF-8
-
sender : the sender of the mail (compulsory, mail without sender will be discarded)
-
recipient : the recipient of the mail. If the mail have several recipients, each recipient will have its own JSON.
-
uid : the UID of the ical (optional)
-
sequence : the sequence of the ical (optional)
-
dtstamp : the date stamp of the ical (optional)
-
method : the method of the ical (optional)
-
recurrence-id : the recurrence-id of the ical (optional)
Example are included in test call ICalToJsonAttributeTest.
Configuration example :
<mailet match=??? class=ICALToJsonAttribute> <sourceAttribute>icalendars</sourceAttribute> <destinationAttribute>icalendarJson</destinationAttribute> </mailet>
ICSSanitizer
Some senders embed 'text/calendar' content as part of Mime bodypart headers with an empty body.
This mailet duplicate the 'text/calendar' content to the Mime body part.
Example configuration:
<mailet match="All" class="ICSSanitizer"/>
LocalDelivery
Receives a Mail from the Queue and takes care of delivery of the message to local inboxes.
LogMessage
Logs Message Headers and/or Body. If the "passThrough" in confs is true the mail will be left untouched in the pipe. If false will be destroyed. Default is true.
MailAttributesListToMimeHeaders
Convert attributes of type Collection<String> to headers
Sample configuration:
<mailet match="All" class="MailAttributesToMimeHeaders"> <simplemapping>org.apache.james.attribute1;headerName1</simplemapping> <simplemapping>org.apache.james.attribute2;headerName2</simplemapping> </mailet>
MailAttributesToMimeHeaders
Convert attributes of type Collection<String> to headers
Sample configuration:
<mailet match="All" class="MailAttributesToMimeHeaders"> <simplemapping>org.apache.james.attribute1;headerName1</simplemapping> <simplemapping>org.apache.james.attribute2;headerName2</simplemapping> </mailet>
MetricsMailet
This Metrics mailet increments a counter on every incoming emails.
This counter is accessible via JMX, or grafana. Read more about metrics.
Example :
<mailet match="all" class="MetricsMailet"> <metricName>relayDenied</metricName> </mailet>
Will increment a counter relayDenied
MailAttributesToMimeHeaders
This mailet replace the mail attribute map of key to MimePart by a map of key to the MimePart content (as bytes).
It takes only one parameter:
-
attribute (mandatory): mime content to be decoded, expected to be a Map<String, byte[]>
Then all this map attribute values will be replaced by their content.
NotifyPostmaster
Sends a notification message to the Postmaster.
A sender of the notification message can optionally be specified. If one is not specified, the postmaster’s address will be used.
The "To:" header of the notification message can be set to "unaltered"; if missing will be set to the postmaster.
A notice text can be specified, and in such case will be inserted into the notification inline text.
If the notified message has an "error message" set, it will be inserted into the notification inline text. If the attachError init parameter is set to true, such error message will be attached to the notification message.
The notified messages are attached in their entirety (headers and content) and the resulting MIME part type is "message/rfc822".
Supports the passThrough init parameter (true if missing).
Sample configuration:
<mailet match="All" class="NotifyPostmaster"> <sender>*an address or postmaster or sender or unaltered, default=postmaster*</sender> <attachError>*true or false, default=false*</attachError> <message>*notice attached to the original message text (optional)*</message> <prefix>*optional subject prefix prepended to the original message, default="Re:"*</prefix> <inline>*default=none*</inline> <attachment>*default=message*</attachment> <passThrough>*true or false, default=true*</passThrough> <fakeDomainCheck>*true or false, default=true*</fakeDomainCheck> <to>*unaltered (optional, defaults to postmaster)*</to> <debug>*true or false, default=false*</debug> </mailet>
The behaviour of this mailet is equivalent to using Resend with the following configuration:
<mailet match="All" class="Resend"> <sender>*an address or postmaster or sender or unaltered*</sender> <attachError>*true or false*</attachError> <message>*<b>dynamically built</b>*</message> <prefix>*a string*</prefix> <passThrough>*true or false*</passThrough> <fakeDomainCheck>*true or false*</fakeDomainCheck> <to>*<b>unaltered or postmaster</b>*</to> <recipients><b>postmaster</b></recipients> <inline>see {@link Resend}</inline> <attachment>see {@link Resend}</attachment> <isReply>true</isReply> <debug>*true or false*</debug> </mailet>
notice, sendingAddress and attachError can be used instead of message, sender and attachError; such names are kept for backward compatibility.
NotifySender
Sends a notification message to the sender of a message.
A sender of the notification message can optionally be specified. If one is not specified, the postmaster’s address will be used.
The "To:" header of the notification message can be set to "unaltered"; if missing will be set to the sender of the notified message.
A notice text can be specified, and in such case will be inserted into the notification inline text.
If the notified message has an "error message" set, it will be inserted into the notification inline text. If the attachError init parameter is set to true, such error message will be attached to the notification message.
The notified messages are attached in their entirety (headers and content) and the resulting MIME part type is "message/rfc822".
Supports the passThrough init parameter (true if missing).
Sample configuration:
<mailet match="All" class="NotifySender"> <sender>*an address or postmaster or sender or unaltered, default=postmaster*</sender> <attachError>*true or false, default=false*</attachError> <prefix>*optional subject prefix prepended to the original message*</prefix> <inline>default=none*</inline> <attachment>default=message*</attachment> <passThrough>*true or false, default=true*</passThrough> <fakeDomainCheck>*true or false, default=true*</fakeDomainCheck> <to>*unaltered or sender or from(optional, defaults to sender)*</to> <debug>*true or false, default=false*</debug> </mailet>
The behaviour of this mailet is equivalent to using Resend with the following configuration:
<mailet match="All" class="Resend"> <sender>*an address or postmaster or sender or unaltered*</sender> <attachError>*true or false*</attachError> <message>*<b>dynamically built</b>*</message> <prefix>*a string*</prefix> <passThrough>true</passThrough> <fakeDomainCheck>*true or false*</fakeDomainCheck> <to>*unaltered or sender or from<*;/to> <recipients><b>sender</b></recipients> <inline>none</inline> <attachment>message</attachment> <isReply>true</isReply> <debug>*true or false*</debug> </mailet>
notice, sendingAddress and attachError can be used instead of message, sender and attachError; such names are kept for backward compatibility.
Null
Simplest Mailet which destroys any incoming messages by setting their state to GHOST.
This effectively stops all processing of this mail.
PostmasterAlias
Rewrites recipient addresses to make sure email for the postmaster is always handled. This mailet is silently inserted at the top of the root spool processor. All recipients mapped to postmaster@<servernames> are changed to the postmaster account as specified in the server conf.
RecipientRewriteTable
Mailet which should get used when using RecipientRewriteTable-Store to implementations for mappings of forwards and aliases.
By specifying an 'errorProcessor' you can specify your logic upon RecipientRewriteTable failures.
Example:
<mailet match="All" class="RecipientRewriteTable"> <errorProcessor>rrt-errors</errorProcessor> </mailet>
The rewriteSenderUponForward option (default to true) can be used to prevent senders to be rewritten upon forwards in the transport envelope (JAMES 3.8.0 default behaviour). WARNING: Please note that not rewriting the sender will cause issues forwarding emails from external senders to external addresses as the DKIM and SPF records will not be matching the ones of the sending domain.
The forwardAutoSubmittedEmails option (default to false) can be used to prevent forwarding bounces as such a scenario can lead to an infinite loop if the forward recipient bounces the email.
Redirect
A mailet providing configurable redirection services.
Can produce listserver, forward and notify behaviour, with the original message intact, attached, appended or left out altogether.
It differs from Resend because (i) some defaults are different, notably for the following parameters: <recipients>, <to>, <reversePath> and <inline>; (ii) because it allows the use of the <static> parameter;.
Use <code>Resend</code> if you need full control, <code>Redirect</code> if the more automatic behaviour of some parameters is appropriate.
This built in functionality is controlled by the configuration as laid out below. In the table please note that the parameters controlling message headers accept the <b>"unaltered"</b> value, whose meaning is to keep the associated header unchanged and, unless stated differently, corresponds to the assumed default if the parameter is missing.
The configuration parameters are:
Property name | explanation |
---|---|
recipients |
A comma delimited list of addresses for recipients of this message; it will use the "to" list if not specified, and "unaltered" if none of the lists is specified. These addresses will only appear in the To: header if no "to" list is supplied. Such addresses can contain "full names", like Mr. John D. Smith <john.smith@xyz.com>. The list can include constants "sender", "from", "replyTo", "postmaster", "reversePath", "recipients", "to", "null" and "unaltered"; "replyTo" uses the ReplyTo header if available, otherwise the From header if available, otherwise the Sender header if available, otherwise the return-path; "from" is made equivalent to "sender", and "to" is made equivalent to "recipients"; "null" is ignored. |
to |
A comma delimited list of addresses to appear in the To: header; the email will be delivered to any of these addresses if it is also in the recipients list. The recipients list will be used if this list is not supplied; if none of the lists is specified it will be "unaltered". Such addresses can contain "full names", like Mr. John D. Smith <john.smith@xyz.com>. The list can include constants "sender", "from", "replyTo", "postmaster", "reversePath", "recipients", "to", "null" and "unaltered"; "from" uses the From header if available, otherwise the Sender header if available, otherwise the return-path; "replyTo" uses the ReplyTo header if available, otherwise the From header if available, otherwise the Sender header if available, otherwise the return-path; "recipients" is made equivalent to "to"; if "null" is specified alone it will remove this header. |
sender |
single email address to appear in the From: and Return-Path: headers and become the sender. It can include constants "sender", "postmaster" and "unaltered"; "sender" is equivalent to "unaltered". Default: "unaltered". |
message |
A text message to insert into the body of the email. Default: no message is inserted. |
inline |
One of the following items: * unaltered The original message is the new message, for forwarding/aliasing * heads The headers of the original message are appended to the message * body The body of the original is appended to the new message * all   ; Both headers and body are appended * none Neither body nor headers are appended </ul> Default: "body". |
attachment |
One of the following items: * heads The headers of the original are attached as text * body The body of the original is attached as text * all Both headers and body are attached as a single text file * none Nothing is attached * message The original message is attached as type message/rfc822, this means that it can, in many cases, be opened, resent, fw’d, replied to etc by email client software. Default: "none". |
passThrough |
true or false, if true the original message continues in the mailet processor after this mailet is finished. False causes the original to be stopped. Default: false. |
fakeDomainCheck |
true or false, if true will check if the sender domain is valid. Default: true. |
attachError |
true or false, if true any error message available to the mailet is appended to the message body (except in the case of inline == unaltered). Default: false. |
replyTo |
A single email address to appear in the Reply-To: header. It can include constants "sender", "postmaster" "null" and "unaltered"; if "null" is specified it will remove this header. Default: "unaltered". |
reversePath |
A single email address to appear in the Return-Path: header. It can include constants "sender", "postmaster" and "null"; if "null" is specified then it will set it to <>, meaning "null return path". Notice: the "unaltered" value is not allowed. Default: the value of the <sender> parameter, if set, otherwise remains unaltered. |
subject |
An optional string to use as the subject. Default: keep the original message subject. |
prefix |
An optional subject prefix prepended to the original message subject, or to a new subject specified with the <subject> parameter. For example: [Undeliverable mail]. Default: ". |
isReply |
true or false, if true the IN_REPLY_TO header will be set to the id of the current message. Default: false. |
debug |
true or false. If this is true it tells the mailet to write some debugging information to the mailet log. Default: false. |
static |
true or false. If this is true it tells the mailet that it can reuse all the initial parameters (to, from, etc) without re-calculating their values. This will boost performance where a redirect task doesn’t contain any dynamic values. If this is false, it tells the mailet to recalculate the values for each e-mail processed. Default: false. |
Example:
<mailet match="RecipientIs=test@localhost" class="Redirect"> <recipients>x@localhost, y@localhost, z@localhost</recipients> <to>list@localhost</to> <sender>owner@localhost</sender> <message>sent on from James</message> <inline>unaltered</inline> <passThrough>FALSE</passThrough> <replyTo>postmaster</replyTo> <prefix xml:space="preserve">[test mailing] </prefix> <!-- note the xml:space="preserve" to preserve whitespace --> <static>TRUE</static> </mailet>
and:
<mailet match="All" class="Redirect"> <recipients>x@localhost</recipients> <sender>postmaster</sender> <message xml:space="preserve">Message marked as spam:</message> <inline>heads</inline> <attachment>message</attachment> <passThrough>FALSE</passThrough> <attachError>TRUE</attachError> <replyTo>postmaster</replyTo> <prefix>[spam notification]</prefix> <static>TRUE</static> </mailet>
replyto can be used instead of replyTo; such name is kept for backward compatibility.
RemoteDelivery
The RemoteDelivery mailet delivers messages to a remote SMTP server able to deliver or forward messages to their final destination.
The remote SMTP server through which each mail is delivered is resolved using MX lookup for each message destination unless the <gateway/> parameter is set. The <gateway/> parameter enables the definition of one or more gateway servers through which all messages are sent.
If an attempt to deliver a message fails, a redelivery attempt is scheduled according to the scheme defined by the <delayTime/> parameter, retrying up to the limit defined by the <maxRetries/> parameter. When the retry limit is exceeded, delivery failure is processed according to the setting of the <bounceProcessor/> parameter.
These are the parameters that control the operation of the RemoteDelivery mailet:
-
outgoing (required) - a String containing the name of the queue that will hold messages being processed by this mailet.
-
bind (optional) - a String describing the local IP address to which the mailet should be bound while delivering emails. This tag is useful for multihomed machines. Default is to bind to the default local address of the machine.<br> Note: The same IP address must be used for all of those RemoteDelivery instances where you explicitly supply a bind address.
-
delayTime (optional) a String containing a comma separated list of patterns defining the number of and delays between delivery attempts. The pattern is [attempts\]delay [unit]* where:
-
attempts (optional) - an Integer for the number of delivery attempts. Default is 1.
-
delay (required) - a Long for the delay between attempts.
-
unit (optional) - a String with the value of one of 'msec', 'sec', 'minute', 'hour', or 'day'. Default is msec.
-
Default is one attempt after 6 hours, which if explicitly declared would be written as <delayTime>1 6 hour</delayTime>
-
maxRetries (optional) an Integer for the number of times an attempt is made to deliver a particular mail. Default is the greater of five and the sum of the attempts for each <delayTime/> specified.
-
maxDnsProblemRetries (optional) - an Integer for the number of times to retry if DNS problems for a domain occur. Default is 0.
-
timeout (optional) - an Integer for the Socket I/O timeout in milliseconds. Default is 180000
-
connectionTimeout (optional) - an Integer for the Socket connection timeout in milliseconds. Default is 60000
-
bounceProcessor (optional) - a String containing the name of the mailet processor to pass messages that cannot be delivered to for DSN bounce processing. Default is to send a traditional message containing the bounce details.
-
onSuccess (optional) - if specified, this processor is called for each email successfully sent to remote third parties.
When using bounceProcessor or onSuccess processors, take special care of error handling (see onMailetException and onMatcherException) to avoid confusing situations. Also remember that on partial delivery, both processors will be used: onSuccess with successfull recipients, and bounceProcessor with failed recipients.
-
startTLS (optional) - a Boolean (true/false) indicating whether the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Default is false.
-
sslEnable (optional) - a Boolean (true/false) indicating whether to use SSL to connect and use the SSL port unless explicitly overridden. Default is false. Setting up to true will result in delivery attempts in SMTPS on port 465 with a fallback to SMTP on port 25. The trust-store if needed can be customized by -Djavax.net.ssl.trustStore=/root/conf/keystore.
-
verifyServerIdentity (optional) - a Boolean (true/false) indicating whether to match the remote server name against its certificate on TLS connections. Default is true. Disabling this runs the risk of someone spoofing a legitimate server and intercepting mails, but may be necessary to contact servers that have strange certificates, no DNS entries, are reachable by IP address only, and similar edge cases.
-
gateway (optional) - a String containing a comma separated list of patterns defining the gateway servers to be used to deliver mail regardless of the recipient address. If multiple gateway servers are defined, each will be tried in definition order until delivery is successful. If none are successful, the mail is bounced. The pattern is host[:port] where:
-
host (required) - the FQN of the gateway server.
-
port (optional) - the port of the gateway server. Default is the value defined in the <gatewayPort/> parameter if set, else the default port for the specified connection type. Default is to resolve the destination SMTP server for each mail using MX lookup.
-
gatewayPort (optional) - an Integer for the gateway port to be used for each defined gateway server for which a port is not explicitly defined in the <gateway/> parameter. Default is the default port for the specified connection type.
-
gatewayUsername (optional) - a String containing the user name to be used to authenticate the user using the AUTH command. Default is not to issue the AUTH command.
-
gatewayPassword (required if gatewayUsername) is set - a String representing the password to be used to authenticate the user using the AUTH command.
-
loadBalancing (optional) - a Boolean (true/false) indicating whether load should be balanced randomly over all defined gateway server. Default is true, false leads to failover only.
-
heloName (optional) - a String containing the name used in the SMTP HELO and EHLO commands. Default is the default domain, which is typically localhost.
-
mail.* (optional) - Any property beginning with mail. described in the Javadoc for package <a href="https://eclipse-ee4j.github.io/angus-mail/docs/api/org.eclipse.angus.mail/org/eclipse/angus/mail/smtp/package-summary.html">*org.eclipse.angus.mail.smtp*</a> can be set with a parameter of the corresponding name. For example the parameter <mail.smtp.ssl.enable>true</mail.smtp.ssl.enable> is equivalent to the Java code props.put("mail.smtp.ssl.enable", "true");. Properties set by this facility override settings made within the mailet code.<br> Note: This facility should be used with extreme care by expert users with a thorough knowledge of the relevant RFCs and the ability to perform their own problem resolutions.
-
debug (optional) - a Boolean (true/false) indicating whether debugging is on. Default is false.
-
usePriority (optional) - a Boolean value (true/false) that indicates whether email priority support is enabled. When the property is set to false, it allows for the disabling of priorities when interacting with unknown third-party systems during remote delivery MX resolution. When this option is enabled, any email will be assigned the lowest priority during retry attempts. Default is false.
Security
You can use the sslEnable parameter described above to force SMTP outgoing delivery to default to SSL encrypted traffic (SMTPS). This is a shortcut for the mail.smtps.ssl.enable javax property.
When enabling SSL, you might need to specify the mail.smtps.ssl.trust property as well. You can also control ciphersuites and protocols via mail.smtps.ssl.ciphersuites and mail.smtps.ssl.protocols properties.
StartTLS can alternatively be enabled upon sending a mail. For this, use the startTls parameter, serving as a shortcut for the javax mail.smtp.starttls.enable property. Depending on how strict your security policy is, you might consider mail.smtp.starttls.required as well. Be aware that configuring trust will then be required. You can also use other javax properties for StartTLS, but their property prefix must be mail.smtp.ssl. in this case.
James enables server identity verification by default. In certain rare edge cases you might disable it via the verifyServerIdentity parameter, or use the mail.smtps.ssl.checkserveridentity and mail.smtp.ssl.checkserveridentity javax properties for fine control.
Read org.eclipse.angus.mail.smtp for full information.
RemoveAllMailAttributes
This mailet sets removes all attributes set on the Mail instance
Sample configuration:
<mailet match="All" class="RemoveAllMailAttributes"/>
RemoveMailAttribute
This mailet sets attributes on the Mail.
Sample configuration:
<mailet match="All" class="RemoveMailAttribute"> <name>attribute_name1</name> <name>attribute_name2</name> </mailet>
RemoveMimeHeader
Remove mime headers from the message (global) and per recipient (specific).
Sample configuration:
<mailet match="All" class="RemoveMimeHeader"> <name>header1,header2</name> </mailet>
RemoveMimeHeader
This mailet removes all of the headers starting with a given prefix in the message (global) and per recipient (specific).
Sample configuration:
<mailet match="All" class="RemoveMimeHeaderByPrefix"> <name>X-APPLICATIVE-HEADER-</name> </mailet>
ReplaceContent
Replace text contents
This mailet allow to specific regular expression to replace text in subject and content.
Each expression is defined as: /REGEX_PATTERN/SUBSTITUTION_PATTERN/FLAGS/
-
REGEX_PATTERN is a regex used for the match
-
SUBSTITUTION_PATTERN is a substitution pattern
-
FLAGS flags supported for the pattern:
-
i: case insensitive
-
m: multi line
-
x: extended (N/A)
-
r: repeat - keep matching until a substitution is possible
-
To identify subject and body pattern we use the tags <subjectPattern> and <bodyPattern>
Rules can be specified in external files. Lines must be CRLF terminated and lines starting with # are considered comments. Tags used to include external files are <subjectPatternFile> and <bodyPatternFile> If file path starts with # then the file is loaded as a resource.
Use of both files and direct patterns at the same time is allowed.
This mailet allow also to enforce the resulting charset for messages processed, when a replacement has been done. To do that the tag <charset> must be specified.
NOTE: Regexp rules must be escaped by regexp escaping rules and applying this 2 additional rules:
-
"/" char inside an expression must be prefixed with "\": e.g: "/\//-//" replaces "/" with "-"
-
when the rules are specified using <subjectPattern> or <bodyPattern> and "/,/" has to be used in a pattern string it must be prefixed with a "\". E.g: "/\/\/,//" replaces "/" with "," (the rule would be "/\//,//" but the "/,/" must be escaped.
Resend
A mailet providing configurable redirection services.
Can produce listserver, forward and notify behaviour, with the original message intact, attached, appended or left out altogether. Can be used as a replacement to {@link Redirect}, having more consistent defaults, and new options available.
Use <code>Resend</code> if you need full control, <code>Redirect</code> if the more automatic behaviour of some parameters is appropriate.
This built in functionality is controlled by the configuration as laid out below. In the table please note that the parameters controlling message headers accept the <b>"unaltered"</b> value, whose meaning is to keep the associated header unchanged and, unless stated differently, corresponds to the assumed default if the parameter is missing.
The configuration parameters are:
Property name | explanation |
---|---|
recipients |
A comma delimited list of addresses for recipients of this message. Such addresses can contain "full names", like Mr. John D. Smith <john.smith@xyz.com>. The list can include constants "sender", "from", "replyTo", "postmaster", "reversePath", "recipients", "to", "null" and "unaltered"; "replyTo" uses the ReplyTo header if available, otherwise the From header if available, otherwise the Sender header if available, otherwise the return-path; "from" is made equivalent to "sender", and "to" is made equivalent to "recipients"; "null" is ignored. Default: "unaltered". |
to |
A comma delimited list of addresses to appear in the To: header. Such addresses can contain "full names", like Mr. John D. Smith <john.smith@xyz.com>. The list can include constants "sender", "from", "replyTo", "postmaster", "reversePath", "recipients", "to", "null" and "unaltered"; "from" uses the From header if available, otherwise the Sender header if available, otherwise the return-path; "replyTo" uses the ReplyTo header if available, otherwise the From header if available, otherwise the Sender header if available, otherwise the return-path; "recipients" is made equivalent to "to"; if "null" is specified alone it will remove this header. Default: "unaltered". |
sender |
A single email address to appear in the From: header and become the sender. It can include constants "sender", "postmaster" and "unaltered"; "sender" is equivalent to "unaltered". Default: "unaltered". |
message |
A text message to insert into the body of the email. Default: no message is inserted. |
inline |
One of the following items: </p> <ul> * unaltered The original message is the new message, for forwarding/aliasing * heads The headers of the original message are appended to the message * body The body of the original is appended to the new message * all   ; Both headers and body are appended * none Neither body nor headers are appended Default: "unaltered". |
attachment |
One of the following items: * heads The headers of the original are attached as text * body The body of the original is attached as text * all Both headers and body are attached as a single text file * none Nothing is attached * message The original message is attached as type message/rfc822, this means that it can, in many cases, be opened, resent, fw’d, replied to etc by email client software. Default: "none". |
passThrough |
true or false, if true the original message continues in the mailet processor after this mailet is finished. False causes the original to be stopped. Default: false. |
fakeDomainCheck |
true or false, if true will check if the sender domain is valid. Default: true. |
attachError |
true or false, if true any error message available to the mailet is appended to the message body (except in the case of inline == unaltered). Default: false. |
replyTo |
A single email address to appear in the Reply-To: header. It can include constants "sender", "postmaster" "null" and "unaltered"; if "null" is specified it will remove this header. Default: "unaltered". |
reversePath |
A single email address to appear in the Return-Path: header. It can include constants "sender", "postmaster" "null" and "unaltered"; if "null" is specified then it will set it to <>, meaning "null return path". Default: "unaltered". |
subject |
An optional string to use as the subject. Default: keep the original message subject. |
prefix |
An optional subject prefix prepended to the original message subject, or to a new subject specified with the <subject> parameter. For example: [Undeliverable mail]. |
isReply |
true or false, if true the IN_REPLY_TO header will be set to the id of the current message. Default: false. |
debug |
true or false. If this is true it tells the mailet to write some debugging information to the mailet log. Default: false. |
Example:
<mailet match="RecipientIs=test@localhost" class="Resend"> <recipients>x@localhost, y@localhost, z@localhost</recipients> <to>list@localhost</to> <sender>owner@localhost</sender> <message>sent on from James</message> <inline>unaltered</inline> <passThrough>FALSE</passThrough> <replyTo>postmaster</replyTo> <prefix xml:space="preserve">[test mailing] </prefix> <!-- note the xml:space="preserve" to preserve whitespace --> <static>TRUE</static> </mailet>
and:
<mailet match="All" class="Resend"> <recipients>x@localhost</recipients> <sender>postmaster</sender> <message xml:space="preserve">Message marked as spam:</message> <inline>heads</inline> <attachment>message</attachment> <passThrough>FALSE</passThrough> <attachError>TRUE</attachError> <replyTo>postmaster</replyTo> <prefix>[spam notification]</prefix> </mailet>
The following example forwards the message without any modification, based on the defaults:
<mailet match="All" class="Resend"/;>
replyto can be used instead of replyTo; such name is kept for backward compatibility.
as the message (or a copy of it) is reinjected in the spool without any modification, the preceding example is very likely to cause a "configuration loop" in your system, unless some other mailet has previously modified something (a header for instance) that could force the resent message follow a different path so that it does not return here unchanged. |
SetMailAttribute
This mailet sets attributes on the Mail.
Sample configuration:
<mailet match="All" class="SetMailAttribute"> <name1>value1</name1> <name2>value2</name2> </mailet>
SetMailAttribute
Adds a specified header and value to the message.
Sample configuration:
<mailet match="All" class="AddHeader"> <name>X-MailetHeader</name> <value>TheHeaderValue</value> </mailet>
Sieve
Execute Sieve scripts for incoming emails, and set the result of the execution as attributes of the mail
Sign
Puts a server-side SMIME signature on a message.
It is a concrete subclass of Sign, with very few modifications to it, to specialize for SMIME.
Handles the following init parameters:
-
<keyHolderClass>: Sets the class of the KeyHolder object that will handle the cryptography functions, for example org.apache.james.security.SMIMEKeyHolder for SMIME.
-
<debug>: if true some useful information is logged. The default is false.
-
<keyStoreFileName>: the {@link java.security.KeyStore} full file name.
-
<keyStorePassword>: the KeyStore password. If given, it is used to check the integrity of the keystore data, otherwise, if null, the integrity of the keystore is not checked.
-
<keyAlias>: the alias name to use to search the Key using {@link java.security.KeyStore#getKey}. The default is to look for the first and only alias in the keystore; if zero or more than one is found a {@link java.security.KeyStoreException} is thrown.
-
<keyAliasPassword>: the alias password. The default is to use the KeyStore password. At least one of the passwords must be provided.
-
<keyStoreType>: the type of the keystore. The default will use {@link java.security.KeyStore#getDefaultType}.
-
<postmasterSigns>: if true the message will be signed even if the sender is the Postmaster. The default is true.
-
<rebuildFrom>: If true will modify the "From:" header. The default is true.
-
<signerName>: the name of the signer to be shown in the explanation text. The default is to use the "CN=" property of the signing certificate.
-
<explanationText>. There is a default explanation string template in English, displaying also all the headers of the original message.
SMIMECheckSignature
Verifies the s/mime signature of a message. The s/mime signing ensure that the private key owner is the real sender of the message. To be checked by this mailet the s/mime signature must contain the actual signature, the signer’s certificate and optionally a set of certificate that can be used to create a chain of trust that starts from the signer’s certificate and leads to a known trusted certificate.
This check is composed by two steps: firstly it’s ensured that the signature is valid, then it’s checked if a chain of trust starting from the signer certificate and that leads to a trusted certificate can be created. The first check verifies that the message has not been modified after the signature was put and that the signer’s certificate was valid at the time of the signing. The latter should ensure that the signer is who he declare to be.
The results of the checks perfomed by this mailet are wrote as a mail attribute which default name is org.apache.james.SMIMECheckSignature (it can be changed using the mailet parameter mailAttribute). After the check this attribute will contain a list of SMIMESignerInfo object, one for each message’s signer. These objects contain the signer’s certificate and the trust path.
Optionally, specifying the parameter strip, the signature of the message can be stripped after the check. The message will become a standard message without an attached s/mime signature.
The configuration parameter of this mailet are summerized below. The firsts defines the location, the format and the password of the keystore containing the certificates that are considered trusted. Note: only the trusted certificate entries are read, the key ones are not.
-
fileType (default: keystore): type of file that is used to construct keystore object. Possible values: keystore, pem.
If fileType is "keystore". The following configuration parameters would be used:
-
keyStoreType (default: jks): Certificate store format . "jks" is the standard java certificate store format, but pkcs12 is also quite common and compatible with standard email clients like Outlook Express and Thunderbird.
-
keyStoreFileName (default: JAVA_HOME/jre/lib/security/cacert): Certificate store path.
-
keyStorePassword (default: ""): Certificate store password.
If fileType is "pem". The following configuration parameters would be used:
-
pemFileName: pem file path.
Other parameters configure the behavior of the mailet:
-
strip (default: false): Defines if the s/mime signature of the message have to be stripped after the check or not. Possible values are true and false.
-
mailAttribute (default: org.apache.james.SMIMECheckSignature): specifies in which attribute the check results will be written.
-
onlyTrusted (default: true): Usually a message signature to be considered by this mailet as authentic must be valid and trusted. Setting this mailet parameter to "false" the last condition is relaxed and also "untrusted" signature are considered will be considered as authentic.
SMIMEDecrypt
This mailet decrypts a s/mime encrypted message. It takes as input an encrypted message and it tries to dechiper it using the key specified in its configuration. If the decryption is successful the mail will be changed and it will contain the decrypted message. The mail attribute org.apache.james.SMIMEDecrypt will contain the public certificate of the key used in the process.
The configuration parameters of this mailet are summarized below. The firsts define the keystore where the key that will be used to decrypt messages is saved.
-
keyStoreType (default: system dependent): defines the type of the store. Usually jks, pkcs12 or pkcs7
-
keyStoreFileName (mandatory): private key store path.
-
keyStorePassword (default: ""): private key store password
The other parameters define which private key have to be used. (if the store contains more than one key).
-
keyAlias: private key alias.
-
keyPass: private key password
SMIMESign
Puts a server-side signature on a message.
It is a concrete subclass of AbstractSign, with very few modifications to it.
A text file with an explanation text is attached to the original message, and the resulting message with all its attachments is signed.
-
The resulting appearance of the message is almost unchanged: only an extra attachment
-
and the signature are added.
The kind of signature depends on the value of the <keyHolderClass> init parameter.
Handles the following init parameters:
-
<keyHolderClass>: Sets the class of the KeyHolder object that will handle the cryptography functions, for example org.apache.james.security.SMIMEKeyHolder for SMIME.
-
<debug>: if true some useful information is logged. The default is false.
-
<keyStoreFileName>: the {@link java.security.KeyStore} full file name.
-
<keyStorePassword>: the KeyStore password. If given, it is used to check the integrity of the keystore data, otherwise, if null, the integrity of the keystore is not checked.
-
<keyAlias>: the alias name to use to search the Key using {@link java.security.KeyStore#getKey}. The default is to look for the first and only alias in the keystore; if zero or more than one is found a {@link java.security.KeyStoreException} is thrown.
-
<keyAliasPassword>: the alias password. The default is to use the KeyStore password. At least one of the passwords must be provided.
-
<keyStoreType>: the type of the keystore. The default will use {@link java.security.KeyStore#getDefaultType}.
-
<postmasterSigns>: if true the message will be signed even if the sender is the Postmaster. The default is true.
-
<rebuildFrom>: If true will modify the "From:" header. The default is true.
-
<signerName>: the name of the signer to be shown in the explanation text. The default is to use the "CN=" property of the signing certificate.
-
<explanationText>. There is a default explanation string template in English, displaying also all the headers of the original message.
SpamAssassin
Sends the message through daemonized SpamAssassin (spamd), visit spamassassin.apache.org for info on configuration. The header X-Spam-Status is added to every message, this contains the score and the threshold score for spam (usually 5.0). If the message exceeds the threshold, the header X-Spam-Flag will be added with the value of YES. The default host for spamd is localhost and the default port is 783.
org.apache.james.spamassassin.status - Holds the status org.apache.james.spamassassin.flag - Holds the flag
Sample Configuration:
<mailet notmatch="SenderHostIsLocal" class="SpamAssassin"> <spamdHost>localhost</spamdHost> <spamdPort>783</spamdPort> </mailet>
StripAttachment
Remove attachments from a Message. Supports simple removal, storing to file, or storing to mail attributes.
Configuration:
<mailet match="All" class="StripAttachment" > <pattern >.*\.xls </pattern> <!-- The regular expression that must be matched -- > <!-- notpattern >.*\.xls </notpattern--> <!-- The regular expression that must be matched -- > <mimeType>text/calendar</mimeType> <!-- The matching mimeType -- > <directory >c:\temp\james_attach </directory> <!-- The directory to save to -- > <remove >all </remove> <!-- either "no", "matched", "all" -- > <!-- attribute>my.attribute.name</attribute --> </mailet >
At least one of pattern, notpattern and mimeType is required.
TextCalendarBodyToAttachment
This mailet converts Content-Type of MimeMessage from text/calendar to mulitpart/mixed
The BodyPart should be retrieved from content of text/calendar with all the same "Content-*" headers from original message and those "Content-" header are removed from original message
It does not takes any parameter
Sample configuration:
<mailet match="All" class="TextCalendarBodyToAttachment"/>
ToProcessor
This mailet redirects the mail to the named processor
Sample configuration:
<mailet match="All" class="ToProcessor"> <processor>spam</processor> <notice>Notice attached to the message (optional)</notice> </mailet>
ToRepository
Stores incoming Mail in the specified Repository.
If the "passThrough" in conf is true the mail will be returned untouched in the pipe and may be processed by additional mailets. If false will be destroyed.
ToSenderDomainRepository
Stores incoming Mail in a repository defined by the sender’s domain.<br>
Supported configuration parameters:
-
"urlPrefix" mandatory: defines the prefix for the per sender’s domain repository. For example for the value 'cassandra://var/mail/sendersRepositories/', a mail sent by 'user@james.org' will be stored in 'cassandra://var/mail/sendersRepositories/james.org'.
-
"passThrough" optional, defaults to false. If true, the processing of the mail continues. If false it stops.
-
"allowRepositoryCreation" optional, defaults to true. If true, non existing repository will be created. In case of misconfiguration, this might lead to arbitrary repository creation. If false, the incoming mails will be stored only in already existing repository. If not existing, the email will be dropped with an appropriate log warning (leading to potential data loss). In case, you want to create a repository manually, make a http PUT request to /mailRepositories/encodedUrlOfTheRepository from web admin api. For example http://ip:port/mailRepositories/file%3A%2F%2FmailRepo
Example:
<mailet match="All" class="ToSenderDomainRepository"> <urlPrefix>cassandra://var/mail/sendersRepositories/</urlPrefix> <passThrough>false</passThrough> <allowRepositoryCreation>true</allowRepositoryCreation> </mailet>
VacationMailet
This mailet uses JMAP VacationResponse and sends back a vacation notice to the sender if needed.
WithPriority
This mailet sets the priority of the incoming mail.
Example configuration:
<mailet match="All" class="WithPriority"> <priority>7</priority> </mailet>
WithStorageDirective
WithStorageDirective position storage directive for the recipients of this email.
These directives are used by <strong>LocalDelivery</strong> mailet when adding the email to the recipients mailboxes.
The following storage directives can be set:
-
targetFolderNames: the folders to append the email in. Defaults to none (INBOX). Coma separated list of folder names. Fallback to targetFolderName.
-
targetFolderName: the folder to append the email in. Defaults to none (INBOX).
-
seen: boolean, whether the message should be automatically marked as seen. Defaults to false.
-
important: boolean, whether the message should be automatically marked as important. Defaults to false.
-
keywords: set of string, encoded as a string (value are coma separated). IMAP user flags to set for the message. Defaults to none
Example:
<mailet match="IsMarkedAsSpam" class="WithStorageDirective"> <targetFolderName>Spam</targetFolderName> <seen>true</seen> <important>true</important> <keywords>keyword1,keyword2</keywords> </mailet>
Alternatively, several target folders can be specified:
<mailet match="IsMarkedAsSpam" class="WithStorageDirective"> <targetFolderNames>Important, INBOX</targetFolderNames> <seen>true</seen> <important>true</important> <keywords>keyword1,keyword2</keywords> </mailet>
Experimental mailets
ClamAVScan
Does an antivirus scan check using a ClamAV daemon (CLAMD)
Interacts directly with the daemon using the "stream" method, which should have the lowest possible overhead.
The CLAMD daemon will typically reside on localhost, but could reside on a different host. It may also consist on a set of multiple daemons, each residing on a different server and on different IP number. In such case a DNS host name with multiple IP addresses (round-robin load sharing) is supported by the mailet (but on the same port number).
Handles the following init parameters:
-
<debug>
-
<host>: the host name of the server where CLAMD runs. It can either be a machine name, such as "java.sun.com", or a textual representation of its IP address. If a literal IP address is supplied, only the validity of the address format is checked. If the machine name resolves to multiple IP addresses, round-robin load sharing will be used. The default is localhost.
-
<port>: the port on which CLAMD listens. The default is 3310.
-
<maxPings>: the maximum number of connection retries during startup. If the value is 0 no startup test will be done. The default is 6.
-
<pingIntervalMilli>: the interval (in milliseconds) between each connection retry during startup. The default is 30000 (30 seconds).
-
<streamBufferSize>: the BufferedOutputStream buffer size to use writing to the stream connection. The default is 8192.
The actions performed are as follows:
-
During initialization:
-
Gets all config.xml parameters, handling the defaults;
-
resolves the <host> parameter, creating the round-robin IP list;
-
connects to CLAMD at the first IP in the round-robin list, on the specified <port>;
-
if unsuccessful, retries every <pingIntervalMilli> milliseconds up to <maxPings> times;
-
sends a PING request;
-
waits for a PONG answer;
-
repeats steps 3-6 for every other IP resolved.
-
For every mail
-
connects to CLAMD at the "next" IP in the round-robin list, on the specified <port>, and increments the "next" index; if the connection request is not accepted tries with the next one in the list unless all of them have failed;
-
sends a "STREAM" request;
-
parses the "PORT *streamPort*" answer obtaining the port number;
-
makes a second connection (the stream connection) to CLAMD at the same host (or IP) on the streamPort just obtained;
-
sends the mime message to CLAMD (using {@link MimeMessage#writeTo(java.io.OutputStream)}) through the stream connection;
-
closes the stream connection;
-
gets the "OK" or "… FOUND" answer from the main connection;
-
closes the main connection;
-
sets the "org.apache.james.infected" mail attribute to either "true" or "false";
-
adds the "X-MessageIsInfected" header to either "true" or "false";
Some notes regarding clamav.conf :
-
LocalSocket must be commented out
-
TCPSocket must be set to a port# (typically 3310)
-
StreamMaxLength must be >= the James config.xml parameter <*maxmessagesize*> in SMTP <*handler*>
-
MaxThreads should? be >= the James config.xml parameter <*threads*> in <*spoolmanager*>
-
ScanMail must be uncommented
Here follows an example of config.xml definitions deploying CLAMD on localhost, and handling the infected messages:
<!-- Do an antivirus scan --> <mailet match="All" class="ClamAVScan" onMailetException="ignore"/> <!-- If infected go to virus processor --> <mailet match="HasMailAttributeWithValue=org.apache.james.infected, true" class="ToProcessor"> <processor> virus </processor> </mailet> <!-- Check attachment extensions for possible viruses --> <mailet match="AttachmentFileNameIs=-d -z *.exe *.com *.bat *.cmd *.pif *.scr *.vbs *.avi *.mp3 *.mpeg *.shs" class="ToProcessor"> <processor> bad-extensions </processor> </mailet>
<!-- Messages containing viruses --> <processor name="virus"> <!-- To avoid a loop while bouncing --> <mailet match="All" class="SetMailAttribute"> <org.apache.james.infected>true, bouncing</org.apache.james.infected> </mailet> <mailet match="SMTPAuthSuccessful" class="Bounce"> <sender>bounce-admin@xxx.com</sender> <inline>heads</inline> <attachment>none</attachment> <notice> Warning: We were unable to deliver the message below because it was found infected by virus(es). </notice> </mailet> <mailet match="All" class="ToRepository"> <repositoryPath>file://var/mail/infected/</repositoryPath> </mailet> <mailet match="All" class="Null" /> </processor>
ClassifyBounce
Assesses the message to determine if it was a hard or soft bounce, and if it was a soft bounce, something of its nature..
Sample configuration:
<mailet match="All" class="ClassifyBounce"> <headerName>X-MailetHeader</headerName> </mailet>
FromRepository
Re-spools Mail found in the specified Repository.
<mailet match="RecipientIs=respool@localhost" class="FromRepository"> <repositoryPath> *repository path* </repositoryPath> <processor> *target processor* </repositoryPath> <delete&t; [true|<b>false</b>] </delete> </mailet>
HeadersToHTTP
Serialise the email and pass it to an HTTP call
Sample configuration:
<mailet match="All" class="HeadersToHTTP"> <url>http://192.168.0.252:3000/alarm</url> <parameterKey>Test</parameterKey> <parameterValue>ParameterValue</parameterValue> <passThrough>true</passThrough> </mailet>
OnlyText
Keep only the text part of a message.
If the message is text only then it doesn’t touch it, if it is a multipart it transform it a in plain text message with the first text part found.
-
text/plain
-
text/html ⇒ with a conversion to text only
-
text/* as is.
Manage Sieve scripts via a mailet
Each user can manage his SIEVE scripts through the ManageSieveMailet
mailet.
To use the manage SIEVE mailet :
-
You need to create the user sievemanager@DOMAIN ( if you don’t, the SMTP server will check the domain, recognize it, and look for an absent local user, and will generate an error ).
-
You can send Manage Sieve commands by mail to sievemanager@DOMAIN. Your subject must contain the command. Scripts need to be added as attachments and need the ".sieve" extension.
To activate a script for a user, you need the following combination :
-
PUTSCRIPT scriptname
-
SETACTIVE scriptname
RecoverAttachment
This mailet takes an attachment stored in an attribute and attach it back to the message
This may be used to place back attachment stripped by StripAttachment and stored in the attribute org.apache.james.mailet.standard.mailets.StripAttachment.saved
<mailet match="All" class="RecoverAttachment" > <attribute>my.attribute.name</attribute> </mailet >
SerialiseToHTTP
Serialise the email and pass it to an HTTP call
Sample configuration:
<mailet match="All" class="SerialiseToHTTP"> <name>URL</name> <value>url where serialised message will be posted</value> <name>ParameterKey</name> <value>An arbitrary parameter be added to the post</value> <name>ParameterValue</name> <value>A value for the arbitrary parameter</value> <name>MessageKeyName</name> <value>Field name for the serialised message</value> <name>passThrough</name> <value>true or false</value> </mailet>
ServerTime
Returns the current time for the mail server.
Sample configuration:
<mailet match="RecipientIs=time@cadenza.lokitech.com" class="ServerTime"/>
SPF
Check the ip, sender, helo against SPF. Add the following attributes to the mail object:
org.apache.james.transport.mailets.spf.explanation org.apache.james.transport.mailets.spf.result
Sample configuration:
<mailet match="All" class="SPF"> <addHeader>true</addHeader> <debug>false</debug> </mailet>
ToPlainText
This mailet converts HTML parts of a message into Plain text.
It starts looking for multipart/alternative containing a text/plain and a text/html part and only keep the text/plain part. Then in a second pass replaces remaining text/html by their textual content, infered by parsing the HTML content and handling common tags.
Eg:
<mailet matcher="All" class="ToPlainText"/>
ToSenderFolder
Receives a Mail from the Queue and takes care to deliver the message to a defined folder of the sender.
You have to define the folder name of the sender.
The flag 'consume' will tell is the mail will be further
processed by the upcoming processor mailets, or not.
<mailet match="RecipientIsLocal" class="ToSenderFolder"> <folder> *Sent Items* </folder> <consume> *false* </consume> </mailet>
UnwrapText
Remove (best effort to) the hardcoded wrapping from a message.
If the text is "format=flowed" then deflows the text. Otherwise it forces a dewrap of the text.
Parameters:
-
quotewidth - when we try to dewrap e quoted text it helps knowing the original with, so we can reconstruct "wrapped wraps" created by multiple wrappings by clients with different original width or simply to the add of the heading ">" that increase the line length.
The value should be "WIDTH+X" if the original length is known, "-X" otherwise.
In the latter case the length of the longer line will be used.
X is the tollerance needed for the quoting chars: if the original width is known the suggested value for X is 2 (because of "> " prefix), otherwise it is suggested to increase it to a value like 10 (-10)
In summary, if the original wrap is known (for example 76, for flowed messages) quotewidth = 78
Otherwise quotewidth = -10
UseHeaderRecipients
Mailet designed to process the recipients from the mail headers rather than the recipients specified in the SMTP message header. This can be useful if your mail is redirected on-route by a mail server that substitutes a fixed recipient address for the original.
To use this, match against the redirection address using the RecipientIs matcher and set the mailet 'class' to UseHeaderRecipients. This will cause the email to be re-injected into the root process with the recipient substituted by all the recipients in the Mail-For, To and Cc headers of the message.
e.g.
<mailet match="RecipientIs=forwarded@myhost" class="UseHeaderRecipients"> </mailet>
SubAddressing
SubAddressing positions a storage directive for the folder this email will be delivered in if the following criteria are met:
-
the sender has requested the storage directive by sending the mail to <strong>
recipient+folder@domain
</strong> instead of justrecipient@domain
; -
the folder <strong>exists</strong> and the recipient has <strong>allowed</strong> the sender to send a mail to that specific folder.
These directives are used by <strong>LocalDelivery</strong> mailet when adding the email to the recipients mailboxes.
The storage directive is recognized when a specific character or character sequence is present in the local part of the recipient address. <strong>By default, it is "+"</strong>.
If the sender is not allowed to send a mail to the specified folder, then the mail is delivered in the recipient’s inbox. Likewise, if the storage directive is empty or absent, the mail will simply be delivered in the recipient’s inbox.
Thus,
-
a mail sent to
recipient+folder@domain
will be delivered to recipient’s folderfolder
if allowed ; -
a mail sent to
recipient+my-super-folder@domain
will be delivered to recipient’s foldermy-super-folder
if allowed ; -
a mail sent to
recipient@domain
orrecipient+@domain
will be delivered to recipient’s inbox.
Any user can position rights for other users and for its different folders. They may create whitelists or blacklists, for one or several folders. In the case where the sender is unknown, the mail will be delivered in the specified folder only if the recipient has allowed everyone for that folder.