Skip to content

Vacation Auto-Responder

A vacation auto-responder is a simple application that automatically responds to emails with a vacation message. It has to know about all incoming emails. So we must add the Message object to its list of objects of interest.

Start by importing the Message class and adding it to the object keys of interest:

 import {
     DeleteRow,
+    Message,
 } from "https://sobamail.com/module/base/v1?sha224=<BASE_HASH>";

export default class Mutator {
     static id = "responder.test.user.app.example.com";
     static name = "Vacation Auto-Responder";
     static version = "1.0.0.0";
     static objects = new Map([
         [ DeleteRow.KEY, false ],
+        [ Message.KEY, false ],
     ]);

Now write the process method so that it replies to all incoming messages:

    // ...
    process(message, metadata) {
        // If you prefer
        soba.log.info("Hello World!");

        // FYI: Show incoming data
        soba.log.info(`metadata: ${JSON.stringify(metadata, null, 2)}`);
        soba.log.info(` message: ${JSON.stringify(message, null, 2)}`);

        let reply = new Message();

        reply.from = [ {address : soba.app.account()} ];
        reply.to = [ {name : message.from[0][0], address : message.from[0][1]} ];
        reply.subject = "Hello World! I'm on Vacation!";

        reply.bodyText = "I am on vacation and will not be able to respond to" +
            " your message in a timely manner." +
            "\nPlease contact me some other time.";

        reply.bodyHtml = "<p>" +
            "I am on vacation and will not be able to respond to" +
            " your message in a timely manner.<br>" +
            "\nPlease contact me some other time." +
            "</p>";

        soba.log.info(
            `Sent vacation response to '${reply.to[0].name} <${reply.to[0].address}>'`);

        soba.mail.send(reply);
    }

    // ...

One last step: refresh the objects of interest of our application. You need to do this every time you change the objects map in developer mode. On production deployments, the Application Manager does this automatically when it instantiates the app.

To do this, go to the Application Manager again and click "Instances". Find your instance id. It should be easy to find, as it should carry a developer mode mark: develmode icon Select it and click "Reload Objects" at the top.

Now test it by sending an email from another account.