Module smtp_server_example

A simple example callback module for gen_smtp_server_session that also serves as documentation for the required callback API.

Behaviours: gen_smtp_server_session.

Description

A simple example callback module for gen_smtp_server_session that also serves as documentation for the required callback API.

Data Types

error_message()

error_message() = {error, string(), #state{options = list()}}

Function Index

code_change/3
handle_AUTH/4
handle_DATA/4
handle_EHLO/3Handle the EHLO verb from the client.
handle_HELO/2Handle the HELO verb from the client.
handle_MAIL/2Handle the MAIL FROM verb.
handle_MAIL_extension/2Handle an extension to the MAIL verb.
handle_RCPT/2
handle_RCPT_extension/2
handle_RSET/1
handle_STARTTLS/1
handle_VRFY/2
handle_error/3
handle_info/2
handle_other/3
init/4Initialize the callback module's state for a new session.
terminate/2

Function Details

code_change/3

code_change(OldVsn::any(), State::#state{options = list()}, Extra::any()) -> {ok, #state{options = list()}}

handle_AUTH/4

handle_AUTH(Type::login | plain | 'cram-md5', Username::binary(), Password::binary() | {binary(), binary()}, State::#state{options = list()}) -> {ok, #state{options = list()}} | error

handle_DATA/4

handle_DATA(From::binary(), To::[binary(), ...], Data::binary(), State::#state{options = list()}) -> {ok, string(), #state{options = list()}} | {error, string(), #state{options = list()}}

handle_EHLO/3

handle_EHLO(Hostname::binary(), Extensions::list(), State::#state{options = list()}) -> {ok, list(), #state{options = list()}} | error_message()

Handle the EHLO verb from the client. As with EHLO the hostname is provided as an argument, but in addition to that the list of ESMTP Extensions enabled in the session is passed. This list of extensions can be modified by the callback module to add/remove extensions.

The return values are {ok, Extensions, State} where Extensions is the new list of extensions to use for this session or {error, Message, State} where Message is the reject message as with handle_HELO.

handle_HELO/2

handle_HELO(Hostname::binary(), State::#state{options = list()}) -> {ok, pos_integer(), #state{options = list()}} | {ok, #state{options = list()}} | error_message()

Handle the HELO verb from the client. Arguments are the Hostname sent by the client as part of the HELO and the callback State.

Return values are {ok, State} to simply continue with a new state, {ok, MessageSize, State} to continue with the SMTP session but to impose a maximum message size (which you can determine , for example, by looking at the IP address passed in to the init function) and the new callback state. You can reject the HELO by returning {error, Message, State} and the Message will be sent back to the client. The reject message MUST contain the SMTP status code, eg. 554.

handle_MAIL/2

handle_MAIL(From::binary(), State::#state{options = list()}) -> {ok, #state{options = list()}} | error_message()

Handle the MAIL FROM verb. The From argument is the email address specified by the MAIL FROM command. Extensions to the MAIL verb are handled by the handle_MAIL_extension function.

Return values are either {ok, State} or {error, Message, State} as before.

handle_MAIL_extension/2

handle_MAIL_extension(Extension::binary(), State::#state{options = list()}) -> {ok, #state{options = list()}} | error

Handle an extension to the MAIL verb. Return either {ok, State} or error to reject the option.

handle_RCPT/2

handle_RCPT(To::binary(), State::#state{options = list()}) -> {ok, #state{options = list()}} | {error, string(), #state{options = list()}}

handle_RCPT_extension/2

handle_RCPT_extension(Extension::binary(), State::#state{options = list()}) -> {ok, #state{options = list()}} | error

handle_RSET/1

handle_RSET(State::#state{options = list()}) -> #state{options = list()}

handle_STARTTLS/1

handle_STARTTLS(State::#state{options = list()}) -> #state{options = list()}

handle_VRFY/2

handle_VRFY(Address::binary(), State::#state{options = list()}) -> {ok, string(), #state{options = list()}} | {error, string(), #state{options = list()}}

handle_error/3

handle_error(Class::gen_smtp_server_session:error_class(), Details::any(), State::#state{options = list()}) -> {ok, State} | {stop, any(), State}

handle_info/2

handle_info(Info::term(), State::term()) -> {noreply, NewState::term()} | {noreply, NewState::term(), timeout() | hibernate} | {stop, Reason::term(), NewState::term()}

handle_other/3

handle_other(Verb::binary(), Args::binary(), State::#state{options = list()}) -> {string(), #state{options = list()}}

init/4

init(Hostname::inet:hostname(), SessionCount::non_neg_integer(), Address::inet:ip_address(), Options::list()) -> {ok, iodata(), #state{options = list()}} | {stop, any(), iodata()}

Initialize the callback module's state for a new session. The arguments to the function are the SMTP server's hostname (for use in the SMTP banner), The number of current sessions (eg. so you can do session limiting), the IP address of the connecting client, and a freeform list of options for the module. The Options are extracted from the callbackoptions parameter passed into the gen_smtp_server_session when it was started.

If you want to continue the session, return {ok, Banner, State} where Banner is the SMTP banner to send to the client and State is the callback module's state. The State will be passed to ALL subsequent calls to the callback module, so it can be used to keep track of the SMTP session. You can also return {stop, Reason, Message} where the session will exit with Reason and send Message to the client.

terminate/2

terminate(Reason::any(), State::#state{options = list()}) -> {ok, any(), #state{options = list()}}


Generated by EDoc