Home Server: EmailManager

This manager is responsible for checking and parsing emails from one or more IMAP accounts, and sending emails using SMTP. All incoming and the vast majority of outgoing emails sent by Ayla are handled by the EmailManager.

Configuring IMAP email accounts

The incoming email accounts are defined under the emailAccounts setting. The main account must have the key "main". For example, to keep checking emails for 2 accounts, one "main" and another for "work":

"emailAccounts": {
    "main": {
        "archiveName": "Archive",
        "inboxName": "Inbox",
        "imap": {
            "host": "MY.IMAP.COM",
            "password": "MY_PASS",
            "port": 993,
            "user": "MY@EMAIL"
        "rules": [
            { "action": "savePictures", "from": "my@friend.com", "hasAttachments": true }
    "work": {
        "archiveName": "All Mail",
        "inboxName": "Inbox",
        "imap": {
            "host": "MY.WORK.IMAP.COM",
            "password": "ANOTHER_PASS",
            "port": 110,
            "user": "MY@WORKMAIL"
        "rules": [
            { "action": "amazon", "from": ["info@amazon.com", "order@amazon.com"] },
            { "action": "zalando", "from": "info@zalando.de", "subject": "Order status" },

Email rules and custom actions

See the rules settings above? They are used to trigger custom email actions based on message parameters. You can have as many rules as you want for each account, and they'll trigger if certain conditions are met.

The first parameter action is mandatory, and defines the name of the coffeescript file inside the /server/emailActions folder. So for example to execute the "savePictures" action you must create a "savePictures.coffee" file.

The following conditions are currently supported:
  • from A string or array of strings containing from addresses. Supports partial address, so an email from abcd@efgh.com will work with a rule having from = "efgh.com".
  • subject A string or array of strings containing subjects. Also supports partials, so email with subject "Your invoice 12345" will match a rule with subject = "invoice".
  • hasAttachments Special condition, if true will require email to have attachments to trigger the rule.

Custom action scripts must have a method (account, messageDetails, callback).

Sending emails

To send an email using the EmailManager, simply trigger the event "emailmanager.send" from anywhere inside Ayla, passing the message object and a callback. This is using the Expresser Mailer module internally, so for more details please check here.

Last edited Feb 8, 2014 at 2:12 AM by igoramadas, version 3


No comments yet.