This project is read-only.

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": "", "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": ["", ""] },
            { "action": "zalando", "from": "", "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 "" file.

The following conditions are currently supported:
  • from A string or array of strings containing from addresses. Supports partial address, so an email from will work with a rule having from = "".
  • 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 3:12 AM by igoramadas, version 3


No comments yet.