> For the complete documentation index, see [llms.txt](https://coldbox-mailservices.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-mailservices.ortusbooks.com/advanced/async-mail.md).

# Async Mail

The module allows you to either send mail asynchronously or queue it in an in-memory queue so it can be delivered by the mail services scheduler. So let's explore the asynchronous nature of cbmailservices.

## Async Mail

You can easily send mail asynchronously via the [ColdBox Async Manager](https://coldbox.ortusbooks.com/digging-deeper/promises-async-programming) using the `sendAsync()` method. This will return to you a ColdBox Future object, which then you can use to setup an async pipeline to p

{% embed url="<https://coldbox.ortusbooks.com/digging-deeper/promises-async-programming>" %}

```javascript
newMail(
	to         : "email@email.com",
	from       : "no_reply@mydomain.com",
	subject    : "Mail Services Rock",
	type       : "html",
	bodyTokens : {
		user    : "Luis",
		product : "ColdBox",
		link    : event.buildLink( 'home' )
	}
)
.setBody("
    <p>Dear @user@,</p>
    <p>Thank you for downloading @product@, have a great day!</p>
    <p><a href='@link@'>@link@</a></p>
")
.sendAsync()
.then( function( mail ){
	// Async pipeline that can process the mail once it is sent.

})
```

## Mail Queue

You can also detach the mail and let the cbmailservices Mail Queue send it for you. The module's mail scheduler runs on a one-minute interval and will send any mail found in the processing queue. All you need to do is use the `queue()` method and be done!

```javascript
var mailId = newMail(
	to         : "email@email.com",
	from       : "no_reply@mydomain.com",
	subject    : "Mail Services Rock",
	type       : "html",
	bodyTokens : {
		user    : "Luis",
		product : "ColdBox",
		link    : event.buildLink( 'home' )
	}
)
.setBody("
    <p>Dear @user@,</p>
    <p>Thank you for downloading @product@, have a great day!</p>
    <p><a href='@link@'>@link@</a></p>
")
.queue();
```

The `queue`method will return back a task ID guid, which you can use to track the task down in your logs or via the Mail Service.

The mail scheduler is on by default for convenience but is only needed when using the asynchronous mail feature. It can be turned off, if desired, by these steps:

1. Open `config/ColdBox.cfc` (CFML) or `config/ColdBox.bx` (BoxLang)
2. In the modulesSettings section, add a key for `cbmailservices` with the property `runQueueTask` set to `false`. See the [Configuration ](/essentials/configuration.md#runqueuetask)section for more details.

```
moduleSettings = {
	cbmailservices : {
		runQueueTask: false
	}
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://coldbox-mailservices.ortusbooks.com/advanced/async-mail.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
