This site is no longer updated.Go to new Conversational Cloud docs

$mail.sendMessage


This method sends an email message via a pre-configured SMTP server.

Before you use this method, make sure you have configured the SMTP server settings via chatbot.yaml or the $mail.config method.

Syntax

The method accepts three arguments:

Argument Description
address String or string array Email recipient or list of recipients.
subject String Message subject.
body String Message body. You can use HTML markup within it.
$mail.sendMessage(
    "user@example.com",
    "We have a unique offer just for you!",
    "March 25 only, 20% off all our business plans!"
);

The method returns an object with the message delivery status property:

  • OK — the message was sent successfully.
  • UNABLE_TO_CONNECT — SMTP server connection failed.
  • INCORRECT_ADDRESS — an empty string was specified as the sender or recipient address.

How to use

init:
    $mail.config(
        "smtp.just-ai.com",
        2525,
        "user@just-ai.com",
        $secrets.get("smtpPassword"),
        "bot@just-ai.com"
    );

theme: /

    state: AttachDocument
        InputFile:
            prompt = Please upload the filled out data processing agreement to the chat.
            varName = fileUrl
            then = /SendDocument

    state: SendDocument
        script:
            $temp.mailResult = $mail.sendMessage(
                "user@example.com",
                "Data processing agreement",
                "Hello! Please find the filled out agreement attached to this message or use this <a href=\"" + $session.fileUrl + "\">link</a>."
            );
        if: $temp.mailResult.status === "OK"
            a: The agreement has been successfully sent to the manager.
        else:
            a: Sorry, email delivery failed.