sendEmail

Description

Send an email. The body can be either a string or the handle of a liquid page. A SMTP server is required.
It's also possible to attach files to the email.

Usage

sendEmail(<OPTIONS>);

Options

NameTypeDescription
toStringrecipient's email
fromStringsender's email
subjectStringsubject of the email
bodyString[Optional] body of the email
page_handleString[Optional] handle of a liquid page
attachmentsHash[Optional] key is the file name, value is the absolute url to the file
smtpHashsettings for the SMTP server. Attributes: address, port,
user_name, password, authentication ('plain'),
enable_starttls_auto (boolean)

Example

{% action "Send an email" %} sendEmail({ to: 'john@doe.net', from: 'jane@doe.net', subject: 'Hello world', body: 'Lorem ipsum', smtp: { address: 'somewhere.net', port: '42', user_name: 'root', password: 'easyone', authentication: 'plain', enable_starttls_auto: true } }); {% endaction %}

🚧

Do not store SMTP settings in the liquid tag

Instead use the site metafields to store them.

{% action "send an email like a boss" %} var emailSettings = getProp('site').metafields.email_settings; sendEmail({ to: 'john@doe.net', from: emailSettings.from, subject: emailSettings.subject, page_handle: 'email-template', attachments: { 'invitation.pdf': 'http://randomkittenpicture.png' }, smtp: { address: emailSettings.smtp_address, port: emailSettings.smtp_port, user_name: emailSettings.smtp_user_name, password: emailSettings.smtp_password, authentication: 'plain', enable_starttls_auto: true } }); {% endaction %}