×

Integrated eMail Support

Using Omni Automation you can construct and manipulate outline documents, apply styles and import data from a variety of sources. And with integrated scripting support for creating and sending email, it becomes easy to automate the sending of content and documents. The following documentation demonstrate how to access and use this ability, beginning with a set of parameters for generating an email.

Constructor

Omni Automation in OmniFocus supports an Email class, design for creating and sending electronic mail messages. To instantiate an instance of this class, it is preceded by the new constructor.

Instance Properties

As with most scriptable objects, an instance of the Email class has properties that define its design and usage. Here is the list of properties for this class:

Instance Functions

The Email class contains a single command generate() for processing instances of the class.

omnifocus://localhost/omnijs-run?script=try%7Bvar%20email%20%3D%20new%20Email%28%29%0Aemail%2Esubject%20%3D%20%22Omni%20Automation%22%0Aemail%2Ebody%20%3D%20%22Greetings%21%5Cn%5CnHere%20are%20my%20suggestions%20regarding%20Omni%20Automation%3A%22%0Aemail%2Ereceiver%20%3D%20%22support%40omnigroup%2Ecom%22%0Aemail%2Egenerate%28%29%7Dcatch%28err%29%7Bconsole%2Elog%28err%29%7D
Basic eMail Script
 

var email = new Email() email.subject = "Omni Automation" email.body = "Greetings!\n\nHere are my suggestions:" email.receiver = "support@omnigroup.com" email.generate()

NOTE: the value of the receiver can be a single email address or an array of email addresses.

Here’s a plug-in that creates a new outgoing mail message containing the contents of the note of the selected task:

Note to eMail
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.note-to-email", "version": "1.0", "description": "This action will add the note text of the selected task to a new outgoing mail message.", "label": "Note to Email", "shortLabel": "Note to Email" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ // action code // selection options: tasks, projects, folders, tags, allObjects var task = selection.tasks[0] var taskTitle = task.name var noteText = task.note if(noteText === ""){ var alertMsg = "The note of the selected task contains no text." new Alert("Missing Data", alertMsg).show() } else { var email = new Email() email.subject = "Note of task “" + taskTitle + "”" email.body = noteText email.receiver = "" email.generate() } }); action.validate = function(selection, sender){ // validation code // selection options: tasks, projects, folders, tags, allObjects return (selection.tasks.length === 1) }; return action; })();

Here’s an example action plug-in that creates a new mail message containing a OmniFocus URL for generating a copy of the selected task:

Send Task Link
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.of.email-task-link", "version": "1.4", "description": "This action will create an email containing a link for generating a copy of the selected task.", "label": "Send Task Link", "shortLabel": "Task Link" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ task = selection.tasks[0] linkStr = "omnifocus:///add?name=" taskName = encodeURIComponent(task.name) linkStr = linkStr + taskName if (task.note.length > 0){ linkStr = linkStr + "¬e=" + encodeURIComponent(task.note) } if (task.dueDate){ linkStr = linkStr + "&due=" + encodeURIComponent(task.dueDate.toLocaleString()) } if (task.deferDate){ linkStr = linkStr + "&defer=" + encodeURIComponent(task.deferDate.toLocaleString()) } if (task.tags.length > 0){ tagNames = task.tags.map(tag => {return tag.name}) tagStr = tagNames.join(",") linkStr = linkStr + "&tags=" + encodeURIComponent(tagStr) } if (task.estimatedMinutes != undefined && task.estimatedMinutes != null){ taskDuration = task.estimatedMinutes linkStr = linkStr + "&estimate=" + String(taskDuration) + "m" } if (task.flagged){ linkStr = linkStr + "&flag=" + "true" } var email = new Email() email.subject = "OmniFocus Task URL" email.body = "<" + linkStr + ">" //email.receiver = "recipient@recipientcompany.com" email.generate() }); action.validate = function(selection, sender){ return (selection.tasks.length === 1 && selection.tasks[0].hasChildren === false) }; return action; })();

Including Attachments

The following are examples of creating and sending mail messages whose contents are derived from the current document.

Send Document Backup
 

/*{ "type": "action", "targets": ["omnifocus"], "author": "Otto Automator", "identifier": "com.omni-automation.send-omnifocus-backup", "version": "1.0", "description": "This action will create a new email message containing a backup copy of the OmniFocus database.", "label": "Send Backup", "shortLabel": "Send Backup" }*/ (() => { var action = new PlugIn.Action(function(selection, sender){ fileTypeID = "com.omnigroup.omnifocus.filetype.ofocus-backup" baseName = "OF Backup" wrapperPromise = document.makeFileWrapper(baseName, fileTypeID) wrapperPromise.then(function(wrapper){ var email = new Email() email.subject = "Export of " + baseName email.body = "Here is a backup of my OmniFocus database:\n\n" email.fileWrappers = [wrapper] email.generate() }) wrapperPromise.catch(function(err){ console.error(err.message) }) }); action.validate = function(selection, sender){ return true }; return action; })();