z_email_server (zotonic_core v1.0.0-rc.17)
Email server. Queues, renders and sends e-mails.
Summary
Functions
Handle a bounce
Convert process state when code is changed
Handle a delivery report from an outside service like mailgun
Generate a new message id
Send an e-mail.
Poll the database queue for any retrys.
Initiates the server.
Check if the received e-mail address is a bounce address
Check if the sender is allowed to send email. Disabled users are only allowed to send mail to themselves or to the admin.
Check if a file is a tempfile of the emailer
Return the max age of a tempfile
Force a poll to send new email
Generate a reply email address for the message-id. Used when reply_to in the email record is set to 'message_id'. Returns an RFC822-formatted mailbox using the address "reply+MessageId@site_email_domain" (optionally with a display-name).
Send an email, generate an unique message-id for it.
Send an email using a predefined unique id. Emails are only sent for enabled senders and non-backup environments.
Starts the server
Return the filename for a tempfile that can be used for the emailer
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.
Types
Functions
Handle a bounce
Convert process state when code is changed
-spec delivery_report(delivery_type(), binary() | undefined, binary(), binary() | undefined) -> ok.
Handle a delivery report from an outside service like mailgun
-spec generate_message_id() -> binary().
Generate a new message id
-spec handle_cast(term(), term()) -> {noreply, term()} | {noreply, term(), timeout() | hibernate} | {stop, term(), term()}.
Send an e-mail.
-spec handle_info(term(), term()) -> {noreply, term()} | {noreply, term(), timeout() | hibernate} | {stop, term(), term()}.
Poll the database queue for any retrys.
Initiates the server.
Check if the received e-mail address is a bounce address
Check if the sender is allowed to send email. Disabled users are only allowed to send mail to themselves or to the admin.
Check if a file is a tempfile of the emailer
Return the max age of a tempfile
-spec poll() -> ok.
Force a poll to send new email
-spec reply_to_message_id(MessageId, Context) -> ReplyToEmail when MessageId :: binary(), Context :: z:context(), ReplyToEmail :: binary().
Generate a reply email address for the message-id. Used when reply_to in the email record is set to 'message_id'. Returns an RFC822-formatted mailbox using the address "reply+MessageId@site_email_domain" (optionally with a display-name).
-spec send(Email, Context) -> {ok, SentEmailId} | {error, Reason} when Email :: #email{to :: list() | string() | binary() | m_rsc:resource_id() | undefined, cc :: list() | string() | binary() | undefined, bcc :: list() | string() | binary() | undefined, from :: binary() | string(), reply_to :: binary() | string() | message_id | undefined, headers :: [{binary(), binary()}], body :: term(), raw :: term(), subject :: iodata() | undefined, text :: iodata() | undefined, html :: iodata() | undefined, text_tpl :: template_compiler:template() | undefined, html_tpl :: template_compiler:template() | undefined, vars :: list(), attachments :: list(), queue :: boolean()}, SentEmailId :: binary(), Context :: z:context(), Reason :: env_backup | sender_disabled.
Send an email, generate an unique message-id for it.
-spec send(EmailId, Email, Context) -> {ok, SentEmailId} | {error, Reason} when EmailId :: binary() | string(), Email :: #email{to :: list() | string() | binary() | m_rsc:resource_id() | undefined, cc :: list() | string() | binary() | undefined, bcc :: list() | string() | binary() | undefined, from :: binary() | string(), reply_to :: binary() | string() | message_id | undefined, headers :: [{binary(), binary()}], body :: term(), raw :: term(), subject :: iodata() | undefined, text :: iodata() | undefined, html :: iodata() | undefined, text_tpl :: template_compiler:template() | undefined, html_tpl :: template_compiler:template() | undefined, vars :: list(), attachments :: list(), queue :: boolean()}, SentEmailId :: binary(), Context :: z:context(), Reason :: env_backup | sender_disabled.
Send an email using a predefined unique id. Emails are only sent for enabled senders and non-backup environments.
Starts the server
Return the filename for a tempfile that can be used for the emailer
This function is called by a gen_server when it is about to terminate. It should be the opposite of Module:init/1 and do any necessary cleaning up. When it returns, the gen_server terminates with Reason. The return value is ignored.