Skip to content

Receiving Email with the Exchange and POP3 Adapters

Note: It is recommended that the Neuron adapter documentation be reviewed before running this sample. The documentation thoroughly describes each adapter individually and describes how to configure each one.

Overview

Neuron ESB can receive emails from an Exchange Server as well as POP3-enabled email servers. When Neuron receives an email, the entire email message is serialized as the body of the ESB message. To process the contents of the email, you have to deserialize the ESB message to the API Neuron.Esb.Mail.EmailMessage:

Neuron.Esb.Mail.EmailMessage email = Neuron.Esb.Mail.EmailMessage.Deserialize(context.Data.InternalBytes);

This code would be used in a code step inside a process. After the email message is deserialized, the body of the email can be saved as the body of the ESB Message:

context.Data.Body = email.Body;

If the email message had any attachments, they can also be accessed as a collection:

context.Properties.Add("EmailAttachments", email.Attachments);

Once you have access to the list of attachments, you can loop through them and process them individually by using the for-each process step.

The Email API has a number of properties that are specific to the received email. These are described in the Exchange and POP3 adapter documentation.

Solution

This sample consists of three adapter endpoints:

  • ExchangeEndpoint
  • POP3Endpoint
  • FileOutEndpoint

The Exchange and POP3 endpoints publish to the ESB with the party ID EmailPublisher and the topic Email. The EmailPublisher is configured to execute one process when publishing messages – Process Email. This process will deserialize the email message into the Email API, copies the email body to the body of the ESB Messasge and then loops through the list of attachments to the email (if any are present). The email body and each attachment are all published to the ESB individually. The FileOutEndpoint subscribes to all the messages and writes them to the file system.

Figure 1: The Try block of the Process Email process as displayed in the Neuron Process designer.

Running the Sample

Prerequisites

  1. To run this sample you must have access to either an Exchange Server or a POP3-enabled email server.

Open the Sample

To open this sample, see the topic Using the Neuron Samples and select the Exchange and POP3 Adapters sample.

Configure Adapter Endpoints

Exchange Adapter

If you are utilizing a Microsoft Exchange Server to test the sample, follow these steps. The first steps walk you through modifying the Security credentials the Exchange Adapter uses for connecting to the Exchange Server. Then you will modify the Exchange Adapter endpoint.

  1. In the Neuron ESB Explorer, navigate to Security->Authentication->Credentials.
  2. Select the security credential Exchange, and set the Username, Password and Domain fields to the account you will use to access the Exchange Server.
  3. After modifying the security credential properties, click the Apply button.
  4. In the Neuron ESB Explorer, navigate to Connections->Endpoints->Adapter Endpoints.
  5. Select the adapter endpoint named ExchangeEndpoint.
  6. Modify the adapter settings as required to connect to the Exchange Server you are accessing for this sample:
  7. You will mostly likely need to modify the Mailbox Account and the Exchange Folder. This property is the mailbox folder the adapter will read messages from.
  8. After modifying the adapter endpoint properties, click the Apply button and save the Neuron Configuration.

POP3 Adapter

If you are utilizing a POP3-enabled email server to test the sample, follow these steps.

  1. In the Neuron ESB Explorer, navigate to Connections->Endpoints->Adapter Endpoints.
  2. Select the adapter endpoint named POP3Endpoint.
  3. Modify the adapter settings as required to connect to the POP3-enable email server you are accessing for this sample:
  4. After modifying the adapter endpoint properties, click the Apply button and save the Neuron Configuration.

File Adapter

Regardless of which email server you use, you need to make sure the FileOutEndpoint is configured correctly. The File Adapter endpoint writes files to the folder C:\FileOut. By default the file adapter will automatically create this folder the first time it attempts to write a file. If you would like the file adapter endpoint to save messages to a different location, modify the file adapter endpoint setting Folder Path.

Run the Sample

The Exchange Adapter reads messages from a specific folder in the Exchange mailbox. Messages can either be copied to this folder or sent to the Inbox from another account. The POP3 Adapter reads messages from the inbox. Any messages in the inbox will be read.

  1. Copy a message to the Exchange mailbox folder the Exchange Adapter endpoint is configured to read messages from.
  2. After the message is removed from the folder, look for the message in the file folder the File Adapter is configured to write messages to (default is C:\FileOut).
  3. Repeat steps 1 & 2 with different types of messages. Use messages with attachments, HTML content and text context.
Was this article helpful?
Dislike 0
Previous: Sending Email with the SMTP Adapter
Next: Exchanging Files with the FTP Adapter