> 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/building-protocols.md).

# Building Protocols

If you want to build your own protocol you will have to do the following

1. Create a class that inherits from `cbmailservices.models.AbstractProtocol`
2. Create the `init()` and `send()` methods
3. Give your protocol a name in the `init()` via the `variables.name` variable.
4. Register it in the `mailers` section of the [configuration](/essentials/configuration.md)

Here are the method signatures of the two methods to implement:

{% tabs %}
{% tab title="BoxLang (.bx)" %}

```java
/**
 * Constructor
 *
 * @properties The protocol properties to instantiate
 */
function init( struct properties = {} ){
    variables.properties = arguments.properties;
    variables.name = "MyProtocol";
    return this;
}

/**
 * Implemented by concrete protocols to send a message.
 *
 * The return is a struct with a minimum of the following two keys
 * - `error` - A boolean flag if the message was sent or not
 * - `messages` - An array of messages the protocol stored if any when sending the payload
 *
 * @payload The paylod object to send the message with
 * @payload.doc_generic cbmailservices.models.Mail
 *
 * @return struct of { "error" : boolean, "messages" : [] }
 */
struct function send( required cbmailservices.models.Mail payload ){

}
```

{% endtab %}

{% tab title="CFML (.cfc)" %}

```javascript
/**
 * Constructor
 *
 * @properties The protocol properties to instantiate
 */
function init( struct properties = {} ){
    variables.properties = arguments.properties;
    variables.name = "MyProtocol";
    return this;
}

/**
 * Implemented by concrete protocols to send a message.
 *
 * The return is a struct with a minimum of the following two keys
 * - `error` - A boolean flag if the message was sent or not
 * - `messages` - An array of messages the protocol stored if any when sending the payload
 *
 * @payload The paylod object to send the message with
 * @payload.doc_generic cbmailservices.models.Mail
 *
 * @return struct of { "error" : boolean, "messages" : [] }
 */
struct function send( required cbmailservices.models.Mail payload ){

}
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The module ships with the `BXMail` protocol (BoxLang's `bx:mail`) and `CFMail` protocol (CFML's `cfmail`). If you're using BoxLang, extend from a `.bx` class file; for CFML engines, use a `.cfc` component file.
{% endhint %}


---

# 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/building-protocols.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.
