Question: I have webscript written in Javascript for send emails. It works pretty well, but I would like to send those emails in background, so that action can not slow further code execution. How can I do that?

Thanks in advance!

Best,
D

Addtional code:

I created sendmail.lib.js which is included in needed js files with following signature:

```
function sendmail(to, subject, nodeRef, templatePath, templateArgs, textIfTemplateNotFound )

```

This function ends with the line:

```
mail.execute(search.findNode(nodeRef));

```

This is the way I need to send e-mails and on very specific events not related to "out-of-the-box" Alfresco events.

Answer: 
Since you're working with an Action, then the answer is very simple. What you want to do is [Asynchronous Execution of your Action](http://wiki.alfresco.com/wiki/Actions_and_Rules#Asynchronous_Action_Execution). Alfresco will then add your action to the async action queue, and will run it as soon as one of the async threads is available.

Instead of

```
 mailAction.execute(node);

```

You instead to

```
 mailAction.executeAsynchronously(node);

```

And that's it! For more information on what you can do with actions in JavaScript, either have a look at the documentation [on the wiki](https://wiki.alfresco.com/wiki/3.0_JavaScript_API#Actions_API), or just read the [ScriptAction source code](https://svn.alfresco.com/repos/alfresco-open-mirror/alfresco/HEAD/root/projects/repository/source/java/org/alfresco/repo/jscript/ScriptAction.java)
You should create a rule, there are two ways of doing it, I wrote it down some time ago, on my personal blog, sorry for doing this kind of ad..here is the link:
[Scheduled Custom Action Alfresco](http://alch3mi5t.blogspot.it/2012/07/scheduled-custom-action-alfresco.html). This works in case you want the mail being sent on a CRON base. Otherwise, if you want to send mail when something happens in the repository, than you can create a rule following these simple steps. [Create Content Rule Alfresco](http://docs.alfresco.com/4.0/index.jsp?topic=/com.alfresco.enterprise.doc/tasks/tuh-contentrule-create.html).
Let me know if helps.