@c This file is part of the Mailfromd manual.
@c Copyright (C) 2011--2025 Sergey Poznyakoff
@c See file mailfromd.texi for copying conditions.
@c *******************************************************************
@pindex calloutd
  The callout verification is usually performed by a special instance of
@command{mailfromd} (@pxref{callout server}).  However, it is also
possible to set up a dedicated callout server on a separate machine.
You can choose to do so, for instance, in order to reduce the load on
the server running @command{mailfromd}.

  This stand-alone callout facility is provided by the
@command{calloutd} daemon.

@menu
* config-calloutd::     Calloutd Configuration.
* invocation-calloutd:: Calloutd Command-Line Options.
* protocol-calloutd::   The Callout Protocol.
@end menu

@node config-calloutd
@section Calloutd Configuration
Main configuration file @file{/etc/mailfromd.conf} is used
(@pxref{Mailfromd Configuration}).  The configuration statements are
basically the same as for @command{mailfromd}.

The address to listen on is defined in the @code{server} statement.
Basically, it is the only statement the configuration file is required
to have.  The minimal configuration can look like:

@example
program calloutd @{
  server @{
    listen inet://198.51.100.1:3535;
  @}
@}  
@end example

To instruct the @command{mailfromd} daemon to use this server, the
following statement should be added to the @file{/etc/mailfromd.conf}
file:

@example
program mailfromd @{
  callout-url inet://198.51.100.1:3535;
@}  
@end example

The @code{server} statement differs a little from the similar
statement for @command{mailfromd}.  This and another
@command{calloutd}-specific statements are described in detail in the
subsections that follow.  The rest of statements is shared with
@command{mailfromd}.  The following table lists all supported
configuration statements along with cross-references to the
correspondent descriptions:

@multitable @columnfractions 0.3 0.6
@headitem Statement @tab Reference
@item @code{acl} @tab @xref{acl statement,Mailutils Configuration File,,
mailutils, GNU Mailutils Manual}.
@item @code{auth} @tab @xref{auth statement, Mailutils Configuration File,,
mailutils, GNU Mailutils Manual}.
@item @code{database} @tab @xref{conf-database}.
@item @code{database-mode} @tab @xref{conf-database,database-mode}.
@item @code{database-type} @tab @xref{conf-database,database-type}.
@item @code{debug} (section) @tab @xref{debug statement, Mailutils Configuration File,,
mailutils, GNU Mailutils Manual}.
@item @code{debug} @tab @xref{conf-calloutd-log}.
@item @code{ehlo-domain} @tab @xref{conf-callout, ehlo-domain}.
@item @code{enable-vrfy} @tab @xref{conf-callout, enable-vrfy}.
@item @code{group} @tab @xref{conf-priv, group}.
@item @code{include} @tab @xref{include, Mailutils Configuration File,,mailutils, GNU Mailutils Manual}.
@item @code{io-timeout} @tab @xref{conf-timeout, io-timeout}.
@item @code{locking} @tab @xref{locking statement, Mailutils Configuration File,,
mailutils, GNU Mailutils Manual}.
@item @code{lock-retry-count} @tab @xref{conf-database, lock-retry-count}.
@item @code{lock-retry-timeout} @tab @xref{conf-database, lock-retry-timeout}.
@item @code{logger} @tab @xref{conf-calloutd-log}.
@item @code{logging} @tab @xref{logging statement, Mailutils Configuration File,,
mailutils, GNU Mailutils Manual}.
@item @code{mailer} @tab @xref{mailer statement, Mailutils Configuration File,,
mailutils, GNU Mailutils Manual}.
@item @code{mail-from-address} @tab @xref{conf-callout, mail-from-address}.
@item @code{pidfile} @tab @xref{conf-calloutd-setup, pidfile}.
@item @code{server} @tab @xref{conf-calloutd-server}.
@item @code{source-ip} @tab @xref{conf-calloutd-setup, source-ip}.
@item @code{smtp-timeout} @tab @xref{conf-timeout}.
@item @code{state-directory} @tab @xref{conf-calloutd-setup, state-directory}.
@item @code{transcript} @tab @xref{conf-calloutd-log},
@item @code{user} @tab @xref{conf-priv, user}.
@end multitable

@menu
* conf-calloutd-setup:: @command{calloutd} General Setup.
* conf-calloutd-server:: The @code{server} Statement.
* conf-calloutd-log:: @command{calloutd} Logging.
@end menu

@node conf-calloutd-setup
@subsection @command{calloutd} General Setup

@deffn {Calloutd Conf} source-ip IP
Sets source IP address for TCP connections.
@end deffn

@deffn {Calloutd Conf} pidfile filename
Defines the name of the file to store PID value in.
@end deffn

@deffn {Calloutd Conf} state-directory dir
Sets the name of the program state directory.  @xref{statedir}.
@end deffn

@node conf-calloutd-server
@subsection The @code{server} statement

The @code{server} statement configures how @command{calloutd} will
communicate with the client @command{mailfromd} server.

@example
@group
server @{
  id @var{name};
  listen @var{url};
  backlog @var{num};
  max-instances @var{num};
  single-process @var{bool};
  reuseaddr @var{bool};
  default @var{bool};
  callout @var{url};
  acl @{ @dots{} @}
@}
@end group
@end example

@deffn {Calloutd Conf} server
  Define a server.  Optional label may follow the @code{server}
  keyword.  The label is ignored.
  
  The substatements in the @code{server} block provide parameters for
configuring this server.  
@end deffn

@deffn {server} id name
  Assign an identifier to this server.  This identifier is used as
a suffix to syslog tag (@pxref{syslog tag}) in messages related to
this server.  For example, if a server block had the following
statement in it:

@example
id main;
@end example

@noindent
then all messages related to this server will be marked with tag
@samp{calloutd#main}.

  The part before the @samp{#} is set using the @code{tag} statement
in @code{logging} block (@pxref{Logging Statement, Mailutils
Configuration File,, mailutils, GNU Mailutils Manual}).
@end deffn

@deffn {server} listen url
Listen for connections on the given @acronym{URL}.
@xref{milter port specification}, for a description of allowed
@var{url} formats.

Example:

@example
listen inet://10.10.10.1:3331;
@end example
@end deffn

@deffn {server} backlog @var{num}
Configures the size of the queue of pending connections.  Default
value is 8.
@end deffn

@deffn {server} max-instances number
Sets the maximum number of instances allowed for this server.
@end deffn

@deffn {server} single-process bool
When set to @samp{yes}, this server will run in @dfn{single-process}
mode, i.e. it will not fork sub-processes to serve requests.  This
option is meant exclusively to assist in debugging
@command{calloutd}.  Don't use it for anything else but for
debugging! 
@end deffn

@deffn {server} reuseaddr bool
When set to @samp{yes}, @command{calloutd} will attempt to reuse
existing socket addresses.  This is the default behavior.
@end deffn

@deffn {server} acl { @var{statements} }
Defines access control list for this server.  @xref{ACL Statement, Mailutils
Configuration File,, mailutils, GNU Mailutils Manual}, for a detailed
discussion.

If the global ACL is defined as well, an incoming connection is
checked against both lists: first the per-server ACL, then the global
one.  The connection will be permitted only if it passes both checks.
@end deffn

@ignore
The following two statements are ignored:

option
default
@end ignore

@node conf-calloutd-log
@subsection @command{calloutd} logging

@deffn {Calloutd Conf} logger mech
Set default logger mechanism.  Allowed values for
@var{mech} are:

@table @asis
@item stderr
Log everything to the standard error.

@item syslog
Log to syslog.

@item syslog:async
Log to syslog using the asynchronous syslog implementation.
@end table

@xref{Logging and Debugging}, for a detailed discussion.
See also @ref{syslog-async, Using non-blocking syslog}, for
information on how to set default syslog implementation at compile time.
@end deffn

@deffn {Calloutd Conf} debug spec
  Set @command{mailfromd} debug verbosity level.  The @var{spec}
must be a valid debugging level specification (@pxref{debugging level specification}).
@end deffn

@deffn {Calloutd Conf} transcript @var{bool}
If the boolean value @var{bool} is @samp{true}, enables the transcript
of call-out SMTP sessions.
@end deffn

@node invocation-calloutd
@section Calloutd Command-Line Options

The @command{calloutd} invocation syntax is:

@example
  calloutd [@var{option}...]
@end example

The following options are available:

@subheading Server configuration modifiers
@table @option
@opsummary{foreground, calloutd}
@item --foreground
Stay in foreground.  When given this option, @command{calloutd} will
not disconnect itself from the controlling terminal and will run in
the foreground.

@opsummary{group, calloutd}
@item -g @var{name}
@itemx --group=@var{name}

Retain the group @var{name} when switching to user
privileges.  @xref{Starting and Stopping}.

@opsummary{pidfile, calloutd}
@item --pidfile=@var{file}
Set pidfile name.  Overrides the @code{pidfile} configuration
statement, which you are advised to use instead (@pxref{conf-base, pidfile}).

@opsummary{resolv-conf-file, calloutd}
@item --resolv-conf-file=@var{file}
Read resolver settings from @var{file}, instead of the default
@file{/etc/resolv.conf}.

@opsummary{source-ip, calloutd}
@item -S @var{ip}
@itemx --source-ip=@var{ip}
Set source address for @acronym{TCP} connections.  Overrides the
@samp{source-ip} configuration statement, which you are advised to use
instead (@pxref{conf-base, source-ip}). 

@opsummary{single-process, calloutd}
@item --single-process
Do not fork sub-processes to serve requests.  This option is meant to
assist in debugging @command{calloutd}.  Don't use it for anything
else but for debugging, as it terribly degrades performance!

@opsummary{state-directory, calloutd}
@item --state-directory=@var{dir}
Set new program state directory.  @xref{statedir, Local state directory}, for
the description of this directory and its purposes.

@opsummary{user, calloutd}
@item -u @var{name}
@itemx  --user @var{name}
Switch to this user's privileges after startup.  Overrides the @code{user}
configuration file statement, which you are advised to use instead
(@pxref{conf-priv, user}).  Default user is
@samp{@value{DEFAULT_USER}}.
@end table

@subheading Logging and debugging options
@table @option
@opsummary{debug, calloutd}
@item -d @var{string}
@itemx --debug=@var{string}
Set debugging level.  @xref{Logging and Debugging}.

@opsummary{log-facility, calloutd}
@item --log-facility=@var{facility}
Output logs to syslog @var{facility}.

@opsummary{log-tag, calloutd}
@item --log-tag=@var{string}
Tag syslog entries with the given @var{string}, instead of the program name.

@opsummary{logger, calloutd}
@item --logger=@var{mech}
Set logger mechanism (@var{mech} is one of @samp{stderr},
@samp{syslog}, @samp{syslog:async}).  @xref{Logging and Debugging}.

@opsummary{syslog, calloutd}
@item --syslog
Selects default syslog mechanism for diagnostic output.

@opsummary{stderr, calloutd}
@item --stderr
Directs all logging to standard output.  Similar to @option{--logger=stderr}.

@opsummary{source-ip, calloutd}
@item -S @var{ip}
@itemx --source-ip=@var{ip}
Set source address for @acronym{TCP} connections.  Overrides the
@samp{source-ip} configuration statement, which you are advised to use
instead (@pxref{conf-base, source-ip}). 

@opsummary{debug-level, calloutd}
@item --debug-level=@var{level}
Set Mailutils debugging level.  See
@uref{http://mailutils.org/wiki/Debug_level}, for a detailed
discussion of @var{level} argument.

@opsummary{source-info, calloutd}
@item --source-info
@itemx --no-source-info
Include @sc{c} source information in debugging messages.  This is
similar to setting @code{line-info yes} in the @code{debug}
configuration block (@pxref{debug statement, line-info,,
mailutils, GNU Mailutils Manual}).

The @option{--no-source-info} can be used to cancel the effect of the
@code{line-info yes} configuration statement.

You do not need this option, unless you are developing or debugging
@command{calloutd}.

@opsummary{transcript, calloutd}
@item -X
@itemx --transcript
@itemx --no-transcript
Enable or disable transcript of the @acronym{SMTP} sessions to the log
channel.  @xref{Logging and Debugging}.
@end table

@subheading Configuration file control
@table @option
@opsummary{config-file, calloutd}
@item --config-file=@var{file}
Load this configuration file.

@opsummary{config-lint, calloutd}
@item --config-lint
Check syntax of configuration files and exit.  Exit code is 0 if the
file or files are OK, and 78 otherwise.

@opsummary{config-verbose, calloutd}
@item --config-verbose
Verbosely log parsing of the configuration files.

@opsummary{no-site-config, calloutd}
@item --no-site-config
@itemx --no-config
Don't load site-wide configuration file.

@opsummary{set, calloutd}
@item --set=@var{param}=@var{value}
Set configuration parameter
@end table

@subheading Informational options
@table @option
@opsummary{config-help, calloutd}
@item --config-help
Show configuration file summary.

@opsummary{show-config-options, calloutd}
@item --show-config-options
Show compilation options.

@opsummary{help, calloutd}
@item -?
@itemx --help
Give a short  help list.

@opsummary{usage, calloutd}
@item --usage
Give a short usage message.

@opsummary{version, calloutd}
@item -V
@itemx --version
Print program version
@end table

@node protocol-calloutd
@section The Callout Protocol

This section describes the protocol used to communicate with the
@command{calloutd} server.

The protocol works over stream-oriented TCP/IP transport.  Either UNIX
or IPv4 socket can be used.  Commands and responses are terminated by
a single CR LF pair.  Each command occupies exactly one line.  If the
server succeeded in executing the command, it replies with a line
starting with the word @samp{OK}.  Depending on the command, this
keyword may be followed by a single space character and additional
information.  More information can be returned in @dfn{unsolicited
replies} before the @samp{OK} line.  Each unsolicited reply line
starts with and asterisk followed by a single horizontal space
character.

On error, the server replies with @samp{NO} followed by a horizontal
space character and human-readable description of the problem.

The valid commands are discussed below.  In examples illustrating the
commands, the lines sent by the client are prefixed with @kbd{C:}, and
lines sent by the server are prefixed with @kbd{S:}.

@deffn Command vrfy @var{email} [@var{parameter}=@var{value}]
Adds @var{email} to the queue of email addresses to be verified.
Available @var{parameter}s are:

@anchor{callout parameters}
@defvr {callout parameter} mode
Sets verification mode for this email address.  Available modes are:

@table @code
@kwindex mxfirst
@kwindex default
@item mxfirst
@itemx default
The default mode.

If the @code{host} option is also given, its argument is taken as
the domain name.  Otherwise, domain part of @var{email} is used. 

The verification goes as follows.  First, determine MX servers for
that domain.  Query each of them in order of increasing priority.
First of them that replies determines the result of the test.

If no MX servers are defined for that domain, look for its @samp{A}
record.  If available, run SMTP probe on that IP.  

@kwindex mxonly
@item mxonly
Query MX servers for the domain specified with the @code{host} option.

@kwindex hostonly
@item hostonly
Query the server whose name or IP address is supplied with the
@code{host} option. 

@kwindex hostfirst
@item hostfirst
The reverse of @code{mxfirst}: first query the host, then the MX
servers.  The domain must be specified using the @code{host} option.
@end table
@end defvr

@defvr {callout parameter} host
Supplies the domain name for @code{mode=mxonly}, and host name or
IP address for @code{mode=hostfirst} and @code{mode=hostonly}.  The use of 
this keyword with any of these modes is mandatory.
@end defvr

@defvr {callout parameter} ehlo
Supplies the value to use as the argument to the SMTP @code{EHLO} command.
@end defvr

@defvr {callout parameter} mailfrom
Supplies the value to use in the SMTP @code{MAIL FROM} command.
@end defvr

@defvr {callout parameter} starttls
Controls whether to use SMTP @code{STARTTLS} command if the server
offers it.  Allowed values are:

@table @code
@kwindex never
@item never
Never use @code{STARTTLS}.

@kwindex always
@item always
Always use @code{STARTTLS}.

@kwindex ondemand
@item ondemand
Use @code{STARTTLS} only if @code{MAIL FROM:} command fails with code
530 (authorization failed).  This is the default.
@end table
@end defvr

On success, the server replies with @samp{OK}, followed by a non-negative
session ID for that email:

@example
@kbd{C:} VRFY gray@@example.org
@kbd{S:} OK 0000000001
@end example
@end deffn

@deffn Command get @var{arg} [@var{arg}]
Query value of internal callout parameters.  Valid values for
@var{arg} are:

@table @asis
@item ehlo
Return the string used as argument to the SMTP @code{EHLO} command.

@item mailfromd
Return the email address that is used in the SMTP @code{MAIL FROM} command.
@end table

On success, the server returns the requested value (if found) in an
unsolicited reply:

@example
@kbd{C:} GET ehlo timeout
@kbd{S:} * ehlo=example.net
@kbd{S:} OK
@end example
@end deffn

@deffn Command sid @var{string}
Sets @var{string} as session identifier for that session.  Example:

@example
@kbd{C:} SID deadbeef
@kbd{S:} OK
@end example
@end deffn

@deffn Command timeout @var{connect} @var{initial} @var{helo} @
 @var{mail} @var{rcpt} @var{rset} @var{quit}
Sets timeouts for various stages of SMTP session.  On success,
@samp{OK} is returned.

@example
@kbd{C:} timeout 300 300 300 600 300 300 120
@kbd{S:} OK timeouts set
@end example
@end deffn

@deffn Command run
Runs callout session for emails registered with the @code{vrfy}
command.  On success, results of the check are returned after the
@samp{OK} keyword in a whitespace-separated list of
@samp{@var{id}=@var{result}} pairs.  In each pair, @var{id} is its
identifier as returned in the reply to the @code{VRFY} command and
@var{result} is one of the following result strings: @samp{success},
@samp{not_found}, @samp{failure}, @samp{temp_failure}, @samp{timeout}.

Additional information about each callout session is returned in
unsolicited replies.  Each such reply is prefixed with the email
identifier and callout stage name.  Stage names are:

@table @code
@item INIT @var{remote_name}
The @command{calloutd} server is establishing communication with the
remote SMTP server @var{remote_name}.

@item GRTNG @var{line}
@command{calloutd} received initial response from the remote server.
@var{line} is the first line of the reply.

@item HELO @var{line}
@command{calloutd} received response to the @code{EHLO} (or
@code{HELO}) command.  In case of multiline response, @var{line} is
the first line.

@item SENT @var{command}
The SMTP command @var{command} has been sent to the remote server.

@item RECV @var{line}
The remote server returned @var{line} in response.  In case of
multiline response, @var{line} is the first line.
@end table

Example of verification session:

@example
@group
@kbd{C:} RUN
@kbd{S:} * 0000000000 INIT mx.example.org
@kbd{S:} * 0000000000 GRTNG 220 mx.example.org ESMTP Ready
@kbd{S:} * 0000000000 HELO 250-mx.example.org Hello tester
@kbd{S:} * 0000000000 SENT RCPT TO:<gray@@example.org>
@kbd{S:} * 0000000000 RECV 250 Accepted
@kbd{S:} * 0000000001 INIT foo.example.net
@kbd{S:} * 0000000001 GRTNG 220 foo ESMTP server ready
@kbd{S:} * 0000000001 HELO 250-foo.example.net Hello
@kbd{S:} * 0000000001 SENT RCPT TO:<gray@@example.net>
@kbd{S:} * 0000000001 RECV 450 4.7.0 You are greylisted for 3600 seconds
OK 0000000000=success 0000000001=temp_failure
@end group
@end example
@end deffn

@deffn Command drop @var{serial}
Drop the email with the given @var{serial} number from the
verification queue.  Example:

@example
@kbd{C:} DROP 0000000002
@kbd{S:} OK
@end example
@end deffn

@deffn Command quit
Finishes the current session and disconnects from the callout server.

@example
@kbd{C:} QUIT
@kbd{S:} OK bye
@end example
@end deffn

