Skip to content

Instantly share code, notes, and snippets.

@mikeclarke
Created September 9, 2013 21:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeclarke/6501852 to your computer and use it in GitHub Desktop.
Save mikeclarke/6501852 to your computer and use it in GitHub Desktop.
Create an Asana project task from the initial email sent to a mailing list. Emails from your company's domain are ignored. Configure this script to run based on an every minute trigger.
function forwardLabelToAsana() {
var asana_email = 'x+FirstNumber@mail.asana.com';
var domain = '@company.com';
var inbound_label = GmailApp.getUserLabelByName('recruiting/recruiting-inbound');
var destination_label = GmailApp.getUserLabelByName('recruiting');
var threads = inbound_label.getThreads();
for (var i = 0; i < threads.length; i++) {
// We only care about the first message in a thread
var messages = threads[i].getMessages();
var msg = messages[0];
var candidate = msg.getFrom()
// Check if email is from us
var from_us = candidate.indexOf(domain);
if (from_us == -1.0) {
Logger.log('creating task for: ' + candidate);
msg.forward(asana_email, {
subject: candidate
});
}
}
// Remove `inbound_label` to avoid re-sending emails to Asana
Logger.log('removing inbound label');
inbound_label.removeFromThreads(threads);
// Apply `destination_label` to processed threads
Logger.log('applying destination label');
destination_label.addToThreads(threads);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment