Email Hooks

autoresponder_delete_pre.sh

This script is called before an autoresponder is deleted.

Environment variables

  • username: Directadmin username/owner of domain
  • domain: domain from which the autoresponder is deleted
  • user: name of autoresponder account

autoresponder_set_(pre|post).sh

This hook is for autoresponder creation and modification.

Environment variables

  • username : DA username
  • domain : domain for which the autoresponder is created
  • user : name of the autoresponder
  • cc (1|0): whether the cc checkbox is set
  • email : cc value set
  • header (1|0): relating to the html/utf-8 autoreplies
  • reply_encoding: encoding used in response
  • reply_content_type: content type of the response (e.g., text/plain)
  • subject: prefix used in the response subject
  • reply_once_time: Minimum time before a repeated reply

email_change_pass_(pre|post).sh

This script is called before/after an email user's password is changed.

Environment variables

  • user : email account user
  • domain : domain where the user is located
  • passwd : new user password... this value is encrypted when password change is coming from a peer via the Multi-Server configuration
  • passwd_is_crypted : if set to 1, passwd is encrypted.
  • quota : email account quota
  • user_can_set_email_limit : directadmin.conf value:user_can_set_email_limit

email_create_(pre|post).sh

This hook is called before/after the virtual email is created.

Environment variables

  • Username: directadmin account
  • user: email account name
  • domain: domain where virtual email is created
  • passwd: password of account
  • passwd_is_crypted(0|1): if set, passwd is encrypted
  • quota: disk quota in Mib for email account (0 is unlimited)
  • limit: daily send limit (0 is unlimited)

email_destroy_(pre|post).sh

This hook script is ran before/after an email account is removed.

Environment variables

  • username: DA user name
  • domain: domain where deleted email account is located
  • user: email account to be deleted

email_filter_write_(pre|post).sh

This hook is called before/after the filter file at /etc/virtual/domain.com/filter is modified.

Environment variables

  • username : owner of domain
  • domain : domain for which the filter is modified
  • adult : set to ON if the adult filter is turned on
  • /etc/virtual/domain.ltd/filter.conf contents for each entry:
    • environment variable key: a number id of the rule
    • type: type of the rule... possible values include the following:
      • domain: domain from which all email would be blocked
      • email: specific email to filter out
      • word: block email if string defined by value is found
      • size: email size limit
    • value: the value for the type
    • example: type=size&value=100
  • The tokens for "filter"... the most useful include the following:
    • DOVECOT (yes|no): is dovecot is used on the server
    • HOME: user's home directory
    • INBOX_SPAM (drop|INBOX.spam): drop spam or save it into INBOX.spam folder
    • MAIL_PARTITION_HOME: folder where users imap folder could be found

forwarder_(create|delete)_(pre|post).sh

These custom scripts are used for creating, setting, and deleting forwarders.

Note that this will also be called when the catch-all is set.

Environment variables

username: DA account name file: domain aliases file (/etc/virtual/domain.com/aliases) user: forwarder name value: (forwarder_create_(pre|post).sh only) address to forward to domain: domain for which forwarder is created


vacation_set_(pre|post).sh

Hook scripts used when the User sets a vacation message (creation or alteration).

Environment variables

  • username: Directadmin username/owner of domain
  • domain: user domain
  • user: email user for which vacation is set
  • text: vacation message
  • return_code(0|1):(post script only) if set to 0, an error occurred during vacation set, but if set to 1, no error resulted
  • start time variables:
    • startyear
    • startmonth
    • startday
    • starttime
  • end time variables:
    • endyear
    • endmonth
    • endday
    • endtime

Email DNS Authentication

dkim_create_post.sh

New hook script, called after the dkim_create.sh has finished running, and was successful.

Use exit 0; for success, and exit with a non-zero for error.

The result will be added to the output regardless, but only shown if there is an error.

Environment variables

  • domain: domain for which DKIM is created

dnssec_sign_post.sh

This script is called after a zone is signed, but before any clustering sends it off to the slave DNS servers.

If all is well, and you want the clustering (if enabled) to proceed, use exit code 0.

If there is an error and you need it to abort the clustering push, then use any non-zero value so that the signing function call will abort after the local file is signed, but before the clustering push happens.

Environment variables

  • domain: domain zone that was signed
  • return_code (0|1): the success/failure of the actual signing... 1 is success, 0 means there was an error.
  • do_cluster (0|1):set to 1 if directadmin.conf cluster=1 AND it's a local trigger. Remote slaves get the raw copy anyway, so do_cluster=0 might only be seen if directadmin.conf cluster=0.
    The only remote case would be remote per-record changes, which has been seldom used, if ever.
    Possible use may be necessary in the future, so just be sure you handle it if you need to do different actions based on this value (e.g., dns-01 wildcard LetsEncrypt requests).

Spam

spamassassin_destroy_pre.sh (rspamd_destroy_pre.sh)

This script is called before spamassassin/rspamd is disabled for domain.

If rspamd is used, the hook script is aptly named rspamd_destroy_pre.sh.

Environment variables

  • username: owner of domain
  • domain: domain for which spamassassin/rspamd is disabled

spamassassin_edit_(pre|post).sh (rspamd_edit_(pre|post).sh)

This hook is run before/after a user modifies spamassasin (rspamd) settings.

If rspamd is used, the hook is aptly named rspamd_edit_(pre|post).sh.

Environment variables

  • where (inbox|delete|spamfolder|userspamfolder): where to send mail marked as spam... options are:
    • inbox : users inbox
    • delete : remove mail completely
    • spamfolder : catch-all spam folder
    • userspamfolder : account's spam folder
  • required_hits (5.0|7.5|10.0|custom): spam score threshold
  • required_hits_custom: whether required_hits is set to custom... custom spam score threshold
  • rewrite_subject (0|1): whether the subject should be rewritten:
    • 0 - leave subject unchanged.
    • 1 - add tags
  • subject_tag: custom tag to be added to the subject if rewrite_subject=1
  • report_safe (0|1|2): How should the spam be delivered
    • 0 - Don't use attachments (dangerous)
    • 1 - Use attachments
    • 2 - Use text-only attachments
  • blacklist_from: list of email addresses that will be blocked. One per line.
  • whitelist_from: list of email addresses that will be allowed through, regardless of content. One per line.

spam_script_chmod_0_post.sh

This hook is related to the directadmin.conf value:parse_php_mail_log_at_limit.

It is run after a spamming script mode bits are set to 0 with chmod 000.

Environment variables

  • script: absolute path to script
  • username: owner of script

Examples

Rename the spam script to flag it as such.

Add the following to spam_script_chmod_0_post.sh, chmod to 700, and then chown to diradmin:

#!/bin/sh
mv ${script} ${script}.${username}.spam
RET=$?
exit $RET
1
2
3
4
Last Updated: 6/23/2021, 9:36:08 PM