Skip to content

Vacation Auto-Responder

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

Let's start by importing the Message class and add it to the object keys of interest:

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

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, let's fill in 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);
    }

    // ...

There it is! One last thing we need to do is to refresh the objects of interest for our application. You need to do this every time you change the objects map in developer mode. On production deployments, this is done automatically by the Application Manager during the app instantiation process.

To do this, go to the Application Manager again, click "Instances", find your instance id, (it should be easy as it should have a developer mode mark: develmode icon) select it and click "Reload Objects" from the top.

Done! Now test it by sending an email from another account.