z_email (zotonic_core v1.0.0-rc.17)

Send e-mail to a recipient. Optionally queue low priority messages.

Summary

Functions

Combine a name and an email address to the format jan janssen <jan@example.com> Uses the rfc822 formatting rules, so names with spaces or special characters are quoted.

If the recipient is an resource id, ensure that it is formatted as an email address.

Return the email address to be used in emails for the given id. The address will be formatted using the recipient's name.

Fetch the e-mail address of the site administrator. This is the email address for display purposes. The admin emails are not send to the wwwadmin_email, as that might not (yet) exist.

Fetch the default From e-mail address. Defaults to noreply@hostname

Send an email message defined by the email record.

Send a simple text message to an email address

Send a simple text message to the administrator

Send a page to an e-mail address, assumes the correct template "mailing_page.tpl" is available. Defaults for these pages are supplied by mod_mailinglist.

Send a html message to an email address, render the message using a template.

Send a html and text message to an email address, render the message using two templates.

Queue a simple text message to an email address

Queue a html message to an email address, render the message using a template.

Queue a html and text message to an email address, render the message using two templates.

Split the name and email from the format jan janssen <jan@example.com>. If just "jan" is given then it is assumed that the name is "" and the address is "jan". The email routines should add the default email domain to the returned email address if it is missing.

Functions

bounce_domain(Context)

-spec bounce_domain(z:context()) -> binary().

combine_name_email(Name, Email)

-spec combine_name_email(Name, Email) -> NameEmail
                            when
                                Name :: binary() | string() | undefined,
                                Email :: binary() | string(),
                                NameEmail :: binary().

Combine a name and an email address to the format jan janssen <jan@example.com> Uses the rfc822 formatting rules, so names with spaces or special characters are quoted.

email_domain(Context)

-spec email_domain(z:context()) -> binary().

ensure_domain(Email, Context)

-spec ensure_domain(binary() | string(), z:context()) -> binary().

ensure_to_email(Email, Context)

-spec ensure_to_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()},
                      z:context()) ->
                         {ok,
                          #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()}} |
                         {error, term()}.

If the recipient is an resource id, ensure that it is formatted as an email address.

format_recipient(RecipientId, Context)

-spec format_recipient(RecipientId, Context) -> {ok, EmailAddress} | {error, Reason}
                          when
                              RecipientId :: m_rsc:resource(),
                              Context :: z:context(),
                              EmailAddress :: binary(),
                              Reason :: enoent | no_email | eacces.

Return the email address to be used in emails for the given id. The address will be formatted using the recipient's name.

get_admin_email(Context)

-spec get_admin_email(z:context()) -> binary().

Fetch the e-mail address of the site administrator. This is the email address for display purposes. The admin emails are not send to the wwwadmin_email, as that might not (yet) exist.

get_email_from(Context)

-spec get_email_from(z:context()) -> binary().

Fetch the default From e-mail address. Defaults to noreply@hostname

send(Email, Context)

Send an email message defined by the email record.

send(MsgId, Email, Context)

send(To, Subject, Message, Context)

Send a simple text message to an email address

send_admin(Subject, Message, Context)

-spec send_admin(iodata(), iodata(), z:context()) -> ok | {error, no_recipient}.

Send a simple text message to the administrator

send_page(Email, Id, Context)

Send a page to an e-mail address, assumes the correct template "mailing_page.tpl" is available. Defaults for these pages are supplied by mod_mailinglist.

send_render(To, HtmlTemplate, Vars, Context)

Send a html message to an email address, render the message using a template.

send_render(To, HtmlTemplate, TextTemplate, Vars, Context)

Send a html and text message to an email address, render the message using two templates.

sendq(To, Subject, Message, Context)

Queue a simple text message to an email address

sendq_render(To, HtmlTemplate, Vars, Context)

Queue a html message to an email address, render the message using a template.

sendq_render(To, HtmlTemplate, TextTemplate, Vars, Context)

Queue a html and text message to an email address, render the message using two templates.

split_name_email(String)

-spec split_name_email(String) -> {Name, Email}
                          when String :: string() | binary(), Name :: binary(), Email :: binary().

Split the name and email from the format jan janssen <jan@example.com>. If just "jan" is given then it is assumed that the name is "" and the address is "jan". The email routines should add the default email domain to the returned email address if it is missing.