---
updatedAt: 2025-07-15T08:58:45.000Z
agentTools:
  projectIndex: https://docs.appery.io/llms.txt
---

# Mail

Mail API

**Mail API** provides the ability to send emails.

> 🚧 Email servers
>
> [Appery.io](https://appery.io/) doesn't provide an email server, instead, it provides the ability to connect to your own email server or any public email servers (e.g. *Gmail*, *Outlook*, etc.).

# Method Summary

**Apperyio.Mail** has the following method(s):

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Method
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        send(params)
      </td>

      <td>
        This method provides ability to send emails.
      </td>
    </tr>
  </tbody>
</Table>

The method sends email via the third-party email server.

## Apperyio.Mail.send(params)

**params** is a JSON object with the following fields:

<Table align={["left","left"]}>
  <thead>
    <tr>
      <th>
        Parameter
      </th>

      <th>
        Description
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        host
      </td>

      <td>
        The host of the email server, e.g. `smtp.gmail.com`
      </td>
    </tr>

    <tr>
      <td>
        port
      </td>

      <td>
        The post of the email server, e.g. `587`\
        Optional, the default value is `587`
      </td>
    </tr>

    <tr>
      <td>
        auth
      </td>

      <td>
        If 'true', attempts to authenticate the username. If true, then a username and password are required. Optional, the default value is "true"
      </td>
    </tr>

    <tr>
      <td>
        username
      </td>

      <td>
        The username of the email server to login with. Optional if auth is "false"
      </td>
    </tr>

    <tr>
      <td>
        password
      </td>

      <td>
        The password of the email server to login with. Optional if auth is "false"
      </td>
    </tr>

    <tr>
      <td>
        tls
      </td>

      <td>
        If 'true', switches the connection to a TLS-protected connection before issuing any login command. Optional, the default value is "true"
      </td>
    </tr>

    <tr>
      <td>
        from
      </td>

      <td>
        Email address of the author of the email. Corresponds to the `From` field in `rfc2822`. Optional if "sender" is set
      </td>
    </tr>

    <tr>
      <td>
        sender
      </td>

      <td>
        Specifies the mailbox of the agent responsible for the actual transmission of the message. Corresponds to the `Sender` field in `rfc2822`. Optional if "from" is set
      </td>
    </tr>

    <tr>
      <td>
        replyTo
      </td>

      <td>
        Indicates the mailbox(es) to which the author of the message suggests that replies be sent. Corresponds to the `Reply-To` field in `rfc2822`. Optional, the default value is `""`
      </td>
    </tr>

    <tr>
      <td>
        to
      </td>

      <td>
        Address(es) of the primary recipient(s) of the message. Corresponds to the `To` field in `rfc2822`
      </td>
    </tr>

    <tr>
      <td>
        cc
      </td>

      <td>
        Addresses of others who are to receive the message, though the content of the message may not be directed at them. Corresponds to the `Cc` field in `rfc2822`
      </td>
    </tr>

    <tr>
      <td>
        bcc
      </td>

      <td>
        Addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message. Corresponds to the `Bcc` field in `rfc2822`
      </td>
    </tr>

    <tr>
      <td>
        subject
      </td>

      <td>
        A short string that identifies the topic of the message. Corresponds to the `Subject` field in `rfc2822`. Optional, the default value is `""`
      </td>
    </tr>

    <tr>
      <td>
        content
      </td>

      <td>
        The body of the message. Optional, the default value is `""`
      </td>
    </tr>

    <tr>
      <td>
        mimeType
      </td>

      <td>
        Mime type of content. Optional, the default value is `"text/plain; charset=UTF-8"`.
      </td>
    </tr>

    <tr>
      <td>
        date
      </td>

      <td>
        Long, is a timestamp that specifies the date and time at which the creator of the message indicated that the message was complete and ready to enter the mail delivery system. Optional, the default value is set as system time. E.g.: `1591074040113 for "2020-06-01T22:00:40-07:00"`
      </td>
    </tr>

    <tr>
      <td>
        headers
      </td>

      <td>
        Dictionary of custom fields. Any value-added here will be added after all previous fields or replaces the fields if `rfc2822` says that it should be only one value. The value in the dictionary could be either **String** or **Array of strings** e.g.:\
        ```
        "headers": {
           "header1": "value1",
           "header2": ["value1", "value2"]
        }
        ```
      </td>
    </tr>
  </tbody>
</Table>

> 📘 Email addresses
>
> Email addresses should comply with the [rfc2822](http://google.com) specification. Correct values:
>
> * <john.smith@gmail.com>
> * "John Smith" <john.smith@gmail.com>
> * John Smith <john.smith@gmail.com>
> * <john.smith@gmail.com>, "John Smith2" <john.smith2@gmail.com>

## Response

There is no response if sending the email was successful.

## Examples

### Simplest *Gmail* Example without Content

The following example sends empty email from **<john.smith@gmail.com>** to **<john1@gmail.com>** using Gmail server:

```javascript Script
var result;
try {
    Apperyio.Mail.send({
        "host": 'smtp.gmail.com',
        "to": 'john1@gmail.com',
        "auth": true,
        "tls": true,
        "username": "john.smith@gmail.com",
        "password": "qwnbctostinpwtej"
    });
    result = "success";
} catch (e) {
    result = JSON.stringify(e);
}
Apperyio.response.success(result, "application/json");
```

### *Gmail* Example with Content

The following example sends an email with the subject and content:

```javascript Script
var result;
try {
    Apperyio.Mail.send({
        "host": 'smtp.gmail.com',
        "to": 'john1@gmail.com',
        "auth": true,
        "tls": true,
        "username": "john.smith@gmail.com",
        "password": "qwnbctostinpwtej",
        "content": 'Hello World',
        "mimeType": "text/plain"
    });
    result = "success";
} catch (e) {
    result = JSON.stringify(e);
}
Apperyio.response.success(result, "application/json");
```

### Full *Gmail* Example

This example uses all the abilities of Appery.io email-sending API:

```javascript Script
var result;
try {
    Apperyio.Mail.send({
        "host": 'smtp.gmail.com',
        "from": '"John Smith" <john.smith.noreply@gmail.com>',
        "to": '"John1" <john1@gmail.com>',
        "auth": true,
        "tls": true,
        "username": "john.smith.noreply@gmail.com",
        "password": "qwnbctostinpwtej",
        "cc": '"John2" <john2@gmail.com>, "John3" <john3@gmail.com>',
        "bcc": '"John4" <john4@gmail.com>',
        "subject": 'subject',
        "replyTo": '"John Smith" <john.smith@gmail.com>',
        "content": '<h1>Hello World<h1>',
        "mimeType": "text/html",
        "date": 1591074040113,
        "headers": {
            "test": "test",
            "test2": ["test", "test2"]
        }
    });
    result = "success";
} catch (e) {
    result = JSON.stringify(e);
}
Apperyio.response.success(result, "application/json");
```