---
schema_version: "1"
id: 3f40afdfea860b410cb98e2ed9033cea583de9e629bc5d6200522d45034a2b6c
title: Sending AS2 Messages and Receiving MDNs
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/as2-connector/latest/as2-connector-example-send.md
canonical_url: https://docs.mulesoft.com/as2-connector/latest/as2-connector-example-send
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 02c5cd4dc980ebd72d9fc9602daacdca261cc790033edafa492fdf9567d138fd
description: MuleSoft Documentation Site
release: "7.0"
latest: true
---
---
product: AS2 Connector
version: 7.0
is-latest-version: true
---

# Sending AS2 Messages and Receiving MDNs

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

These examples show how to use Anypoint Connector for AS2 (AS2 Connector) to send AS2 messages to a
trading partner and receive Message Disposition Notifications (MDNs) in response:

- [Send with Synchronous MDN](#send-with-synchronous-mdn)

  Send an AS2 message and receive a synchronous MDN in response.

- [Send with Asynchronous MDN](#send-with-asynchronous-mdn)

  Send an AS2 message and receive an asynchronous MDN in response.

## Send with Synchronous MDN

To create this example, start a new Mule project and configure the `http:listener` source and the
Logger component.

The image shows the Anypoint Studio flow for this example:

![Anypoint Studio flow for sending AS2 messages and receiving synchronous MDNs](/mulesoft/current/en-us/as2-connector/latest/_images/as2-connector-example-sync-flow.png)

### Create a Flow to Send an AS2 Message

Follow these steps to configure the `http:listener` source to initiate a Mule flow when a call is
made to the `/sendSyncFlow` path on localhost port 8082:

1.  Drag the HTTP listener from the Mule Palette onto the canvas.

2.  Optionally, change the display name on the properties window for the listener and click **OK**.

3.  Set the **Path** field to `/sendSyncFlow`.

4.  Click the plus sign (**+**) next to the **Connector configuration** field to configure a global
    element that can be used by all instances of the HTTP listener.

5.  On the **General** tab, accept the defaults and click **OK**.

### Add the Send with Synchronous MDN Operation

Follow these steps to add the **Send with Sync MDN** operation and configure it to send MDNs to the
receiving endpoint of `partnera`:

1.  Drag the **Send with Sync MDN** operation next to the listener component on the canvas.

2.  Click the plus sign (**+**) next to the **Connector configuration** field to configure a global
    element for the **Send with Sync MDN** operation.

3.  Configure the connection by setting the **Partner URL** field to
    `http://localhost:8081/as2-receive` on the **General** tab.

4.  Specify the self and partner credentials.

    Configure these fields in the **Self Config** section:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p>AS2 Partner Name</p></td><td><p>partnerb</p></td></tr><tr><td><p>x509 Alias</p></td><td><p>partnerb</p></td></tr><tr><td><p>email</p></td><td><p><a href="mailto:support@partnerb.com">support@partnerb.com</a></p></td></tr></tbody></table>

    Configure these fields in the **Partner Config** section:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p>AS2 Partner Name</p></td><td><p>partnera</p></td></tr><tr><td><p>x509 Alias</p></td><td><p>partnera</p></td></tr><tr><td><p>email</p></td><td><p><a href="mailto:support@partnera.com">support@partnera.com</a></p></td></tr></tbody></table>

5.  If you want to use algorithms, configure them in the **Requester Config** section.

6.  In the **Keystore** section, apply these values to the keystore that contains the certificates
    and keys:

    <table><colgroup><col> <col></colgroup><thead><tr><th>Field</th><th>Value</th></tr></thead><tbody><tr><td><p>Keystore Password</p></td><td><p>test</p></td></tr><tr><td><p>Keystore Path</p></td><td><p>as2/partnerb.p12</p></td></tr><tr><td><p>Private Key Password</p></td><td><p>test</p></td></tr></tbody></table>

### Add the Logger Component

Add the logger component and configure it to log a message when the app sends an AS2 message and
receives a synchronous MDN.

1.  From the Mule Palette, select **Core** and drag the logger component next to the **Send with
    Sync MDN** operation.

2.  Set the message for the logger to `Message Sent and MDN Received!`.

### Save and Test the Mule App

Follow these steps to deploy your application locally and verify that it correctly sends AS2
requests and receives synchronous MDNs.

1.  Save the project.

2.  Run the app by clicking the project name in **Package Explorer** and then clicking **Run** >
    **Run As** > **Mule Application**.

    If the application starts correctly, the console shows a success message.

3.  Test the app by opening `http://localhost:8082/sendSyncFlow` from a browser or an app like
    Postman.

You can now send AS2 requests to the endpoint configured in the
[Receiving AS2 Messages and Sending Back MDNs](https://docs.mulesoft.com/as2-connector/latest/as2-connector-example-receive-send#receiving-messages-example)
example. With the example running, you can observe the message sent by the **Send with Sync MDN**
operation.

### XML for the Sending Synchronous AS2 MDNs Example

Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:as2-mule4="http://www.mulesoft.org/schema/mule/as2-mule4" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/as2-mule4 http://www.mulesoft.org/schema/mule/as2-mule4/current/mule-as2-mule4.xsd">
	<http:listener-config name="HTTP_Client_Config" doc:name="HTTP Listener config" >
		<http:listener-connection host="0.0.0.0" port="8082" />
	</http:listener-config>
	<as2-mule4:send-config name="AS2_Client_Send_Sync" doc:name="AS2 Connector Send config" >
		<as2-mule4:connection partnerURL="http://localhost:8081/as2-receive" />
		<as2-mule4:self-config as2Name="partnerb" x509Alias="partnerb" email="support@partnerb.com" />
		<as2-mule4:partner-config as2Name="partnera" x509Alias="partnera" email="support@partnera.com" />
		<as2-mule4:requester-config messageIntegrityCheckAlgorithm="SHA512" mdnMessageIntegrityCheckAlgorithm="SHA512" encryptionAlgorithm="DES_EDE3" requestReceipt="SIGNED_REQUIRED" />
		<as2-mule4:keystore-config keystorePassword="test" keystorePath="as2/partnerb.p12" privateKeyPassword="test" />
	</as2-mule4:send-config>
	<flow name="SendSyncFlow" >
		<http:listener doc:name="/sendSyncFlow" config-ref="HTTP_Client_Config" path="/sendSyncFlow" />
		<as2-mule4:send-with-sync-mdn doc:name="Send with Sync MDN" config-ref="AS2_Client_Send_Sync"/>
		<logger level="INFO" doc:name="Message Sent and MDN Received!" message="Message Sent and MDN Received!" />
	</flow>
</mule>
```

## Send with Async MDN

This example follows the same structure as the [Send with Sync MDN](#send-with-synchronous-mdn)
example but incorporates these changes:

- The **Send with Async MDN** operation is used instead of the **Send with Sync MDN** operation.

- A value is specified for the **Receipt delivery url** field. The field can be configured in the
  global element for the **Send with Async MDN** operation or in the properties window.

The image shows the Anypoint Studio flow for this example:

![Anypoint Studio flow for sending AS2 messages and receiving asynchronous MDNs](/mulesoft/current/en-us/as2-connector/latest/_images/as2-connector-example-async-flow.png)

### XML for the Sending AS2 Asynchronous MDNs Example

Paste this code into your Studio XML editor to quickly load the flow for this example into your Mule
app:

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:as2-mule4="http://www.mulesoft.org/schema/mule/as2-mule4" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/as2-mule4 http://www.mulesoft.org/schema/mule/as2-mule4/current/mule-as2-mule4.xsd">
	<http:listener-config name="HTTP_Client_Config" doc:name="HTTP Listener config" >
		<http:listener-connection host="0.0.0.0" port="8082" />
	</http:listener-config>
	<as2-mule4:send-config name="AS2_Client_Send_Sync" doc:name="AS2 Connector Send config" >
		<as2-mule4:connection partnerURL="http://localhost:8081/as2-receive" />
		<as2-mule4:self-config as2Name="partnerb" x509Alias="partnerb" email="support@partnerb.com" />
		<as2-mule4:partner-config as2Name="partnera" x509Alias="partnera" email="support@partnera.com" />
		<as2-mule4:requester-config messageIntegrityCheckAlgorithm="SHA512" mdnMessageIntegrityCheckAlgorithm="SHA512" encryptionAlgorithm="DES_EDE3" requestReceipt="SIGNED_REQUIRED" />
		<as2-mule4:keystore-config keystorePassword="test" keystorePath="as2/partnerb.p12" privateKeyPassword="test" />
	</as2-mule4:send-config>
	<flow name="SendSyncFlow" >
		<http:listener doc:name="/sendAsyncFlow" config-ref="HTTP_Client_Config" path="/sendAsyncFlow" />
		<as2-mule4:send-with-async-mdn doc:name="Send with Async MDN" config-ref="AS2_Client_Send_Sync" receiptDeliveryUrl="http://localhost:8082/receiveMDN"/>
		<logger level="INFO" doc:name="Message Sent!" message="Message Sent!" />
	</flow>
</mule>
```

### Save and Test the Mule App

Follow these steps to deploy your application locally and verify that it correctly sends AS2
requests and receives asynchronous MDNs.

1.  Save the project.

2.  Run the app by clicking the project name in **Package Explorer** and then clicking **Run** >
    **Run As** > **Mule Application**.

    If the application starts correctly, the console shows a success message.

3.  Test the app by opening `http://localhost:8082/sendAsyncFlow` from a browser or an app like
    Postman.

You can now send AS2 requests to the endpoint configured in the
[Receiving AS2 Messages and Sending Back MDNs](https://docs.mulesoft.com/as2-connector/latest/as2-connector-example-receive-send#receiving-messages-example)
example. With the example running, you can observe the message sent by the **Send with Async MDN**
operation.

The MDN is omitted from the logs because it’s routed to the `receiptDeliveryUrl` shown in the
[Receiving AS2 MDNs](https://docs.mulesoft.com/as2-connector/latest/as2-connector-example-receiving-mdn-messages) example.

## See Also

- [AS2 Connector Examples](https://docs.mulesoft.com/as2-connector/latest/as2-connector-examples)

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
