Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
Created July 4, 2016 17:41
Show Gist options
  • Save drewmccormack/d42a75cd3b7764530820194f4eb06627 to your computer and use it in GitHub Desktop.
Save drewmccormack/d42a75cd3b7764530820194f4eb06627 to your computer and use it in GitHub Desktop.
Javascript (JXA) script to send attached files one per email
// Open in Script Editor, and Export as an Application
// To use, drag files from folder onto Droplet
function openDocuments(docs) {
var mail = Application("Mail")
for (var i = 0; i < docs.length; i++) {
var doc = docs[i].toString()
var filename = doc.replace(/^.*[\\\/]/, '')
var message = mail.OutgoingMessage({
subject: filename,
visible: true,
sender: "me@mycompany.com"
})
mail.outgoingMessages.push(message)
var recipient = mail.Recipient({address:"recipient@othercompany.com"})
message.toRecipients.push(recipient)
var attachment = mail.Attachment({fileName:doc})
message.attachments.push(attachment)
mail.activate()
delay(2) // Allow attachment to be copied in
message.send()
}
}
// To test:
// var docs = [Path("/Path/to/a/test/attachment")]
// openDocuments(docs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment