Module gen_smtp_server

A non-blocking tcp listener for SMTP connections.

Behaviours: gen_server.

Description

A non-blocking tcp listener for SMTP connections. Based on the tcp_listener module by Serge Aleynikov http://www.trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles

Data Types

listener()

listener() = #listener{hostname = list(), port = port(), sessionoptions = [tuple()], socket = port() | any(), listenoptions = [tuple()]}

options()

options() = [{domain, string()} | {address, {pos_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}} | {port, pos_integer()} | {protocol, tcp | ssl} | {sessionoptions, [any()]}]

Function Index

init/1 The gen_smtp_server is given a list of tcp listener configurations.
sessions/1Return the list of active SMTP session pids.
start/1Start the listener with callback module Module with default options linked to no process.
start/2Start the listener with callback module Module with options Options linked to no process.
start/3Start the listener as a registered process with callback module Module with options Options linked to no process.
start_link/1Start the listener with callback module Module with default options linked to the calling process.
start_link/2Start the listener with callback module Module on with options Options linked to the calling process.
start_link/3Start the listener as a registered process with callback module Module on with options Options linked to the calling process.
stop/1Stop the listener pid() Pid with reason normal.

Function Details

init/1

init(Args::list()) -> {ok, #state{listeners = [listener()], module = atom(), sessions = [pid()]}} | {stop, any()}

The gen_smtp_server is given a list of tcp listener configurations. You'll typically only want to listen on one port so your options will be a single-item list containing a proplist. e.g.:

  [[{port,25},{protocol,tcp},{domain,"myserver.com"},{address,,{0,0,0,0}}]]
By providing additional configurations the server will listen on multiple ports over either tcp or ssl on any given port. e.g.:
   [
     [{port,25},{protocol,tcp},{domain,"myserver.com"},{address,{0,0,0,0}}],
     [{port,465},{protocol,ssl},{domain,"secure.myserver.com"},{address,{0.0.0.0}}],
     [{port, 25},{family, inet6},{domain,"ipv6.myserver.com"},{address,"::"}]
   ]
  
Note that the default port to listen on is 2525 because the regular SMTP ports are privileged and only bindable by root. The default protocol is tcp, the default listen address is 0.0.0.0 and the default address family is inet. Anything passed in the sessionoptions option, is passed through to gen_smtp_server_session.

See also: gen_smtp_server_session.

sessions/1

sessions(Pid::pid()) -> [pid()]

Return the list of active SMTP session pids.

start/1

start(Module::atom()) -> {ok, pid()} | ignore | {error, any()}

Start the listener with callback module Module with default options linked to no process.

start/2

start(Module::atom(), Options::[options()]) -> {ok, pid()} | ignore | {error, any()}

Start the listener with callback module Module with options Options linked to no process.

start/3

start(ServerName::{local, atom()} | {global, any()}, Module::atom(), Options::[options()]) -> {ok, pid()} | ignore | {error, any()}

Start the listener as a registered process with callback module Module with options Options linked to no process.

start_link/1

start_link(Module::atom()) -> {ok, pid()} | ignore | {error, any()}

Start the listener with callback module Module with default options linked to the calling process.

start_link/2

start_link(Module::atom(), Options::[options()]) -> {ok, pid()} | ignore | {error, any()}

Start the listener with callback module Module on with options Options linked to the calling process.

start_link/3

start_link(ServerName::{local, atom()} | {global, any()}, Module::atom(), Options::[options()]) -> {ok, pid()} | ignore | {error, any()}

Start the listener as a registered process with callback module Module on with options Options linked to the calling process.

stop/1

stop(Pid::pid()) -> ok

Stop the listener pid() Pid with reason normal.


Generated by EDoc