mail egress connector

Mail Egress Connector

Version: 17.01

Supported Since: 17.01

What is Mail Egress Connector?

The Mail Egress Connector can be used to send emails using UltraESB-X via a mail server.

Sample Use case

For using the Mail Egress Connector, you must first select the Mail Connector dependency from the connectors list when creating an empty Ultra project. If you have already created a project, you can add the Mail Connector dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list, select the Mail Connector dependency.

A minimal configuration for the Mail Egress Connector consists of the following:

  • Protocol

  • Host

  • Port

  • User

  • Password

In addition, at least one of the To, CC or BCC fields may need to be specified as the email recipient. If none is specified, the destination address of the message will be used as the To address of the outbound email. Some mail server implementations may also require a suitable From address for the outbound email.

If the mail service is accessible only over SSL (as is the case with mail providers like Gmail or Yahoo), an Other Settings Map containing mail.<protocol>.starttls.enable set to true will also have to be specified. The Other Settings Map can also be useful for specifying other custom transport-related parameters, such as standard JavaMail parameters.

In order to trigger the mail sending flow, let’s start with a Timer Task Listener as the ingress connector for the flow (which will generate only a single "tick", Polling Repeat Count having been set to 0, hence sending out only one test email):

Polling Start Delay (ms)

1000

Polling Repeat Interval (ms)

1000

Polling Repeat Count

0

Concurrent Polling Count

1

Concurrent Execution Limit

4

Since the inbound message from the Timer Task Listener has no payload, let’s add a String Payload Setter to populate the message with a test payload string (which will be made available as the body of the email):

String Payload

test payload

If the payload is of text/html content type, a multipart email would be generated appropriately, but otherwise a plaintext email would be generated with the raw message payload as the email body.

If attachments are available in the UltraESB-X message received by the Mail Egress Connector, they would be attached to the outbound email. Add a File Attacher element to attach a file from a known location to the message:

File Path

/tmp/test.txt

Use File Name as Attachment Name

true

Also, create a file /tmp/test.txt with some sample text, to be picked by the File Attacher.

Finally, let’s add a Mail Egress Connector for sending out the enriched message as an email, with the following configurations:

Transport

Protocol

smtp

Host

smtp.gmail.com

Port

25

User

myemailaddress@gmail.com

Password

thisisnotmypassword

Other Settings

mail-sender-props (Map)

Basic

From

myemailaddress@gmail.com

Reply-To

reply-to-address@mail.com

To

to-address@mail.com

BCC

bcc-address1@mail.com, bcc-address2@mail.com

Subject

Test Subject

(Replace the email account user, password and the From, Reply-To and destination email addresses as per your choice.)

To define the mail-sender-props Map resource, use the Map button on the project.xpml editor:

mail.smtp.starttls.enable

true

The final flow would resemble the following:

mail egress flow

For this exercise, in order to see the actual email sending in action, let’s increase the log level of the mail transport by updating src/test/resources/log4j2.xml:

log4j2.xml (src/test/resources/)

<Configuration ...>
    ...
    <Loggers>
        ...
        <AsyncLogger name="org.adroitlogic.x.transport.mail" level="TRACE"/>

Now, after creating a run configuration and running the project, you will be able to see an email being composed and sent via the configured email account:

2017-01-24T14:22:00,791 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000D000] DEBUG MailTransportSender Composing outbound email using message cf801ad2-4e57-ce6c-0000-000000000001
2017-01-24T14:22:00,810 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender From aliceandbob2016@gmail.com
2017-01-24T14:22:00,811 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender Reply-To janakaud@gmail.com
2017-01-24T14:22:00,812 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender To [aliceandbob2016@gmail.com]
2017-01-24T14:22:00,813 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender BCC [janakaud@gmail.com]
2017-01-24T14:22:00,813 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender Subject Test Subject
2017-01-24T14:22:00,813 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender Adding attachment test.txt
2017-01-24T14:22:00,816 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender Adding payload as plaintext
2017-01-24T14:22:00,816 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000D000] DEBUG MailTransportSender Composed outbound email using message cf801ad2-4e57-ce6c-0000-000000000001
2017-01-24T14:22:00,816 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000T000] TRACE MailTransportSender Sending email for message cf801ad2-4e57-ce6c-0000-000000000001 to [aliceandbob2016@gmail.com] BCC [janakaud@gmail.com]
...
DEBUG SMTP: connected to host "smtp.gmail.com", port: 25
...
DEBUG SMTP: AUTH LOGIN succeeded
...
MAIL FROM:<aliceandbob2016@gmail.com>
250 2.1.0 OK 63sm25307141wmg.2 - gsmtp
RCPT TO:<aliceandbob2016@gmail.com>
...
Subject: Test Subject
MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_Part_0_1635565058.1485247920799"
...
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

test payload
...
Content-Type: text/plain; charset=us-ascii; name=test.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename=test.txt

test attachment
...
250 2.0.0 OK 1485247935 63sm25307141wmg.2 - gsmtp
DEBUG SMTP: message successfully delivered to mail server
...
2017-01-24T14:22:11,139 [127.0.1.1-janaka-ENVY] [pool-2-thread-1] [mail-sample-17.01-beta6] [000000D000] DEBUG MailTransportSender Successfully sent email for message cf801ad2-4e57-ce6c-0000-000000000001 to [aliceandbob2016@gmail.com] BCC [janakaud@gmail.com]

Now check the email accounts under the To and BCC fields, to verify that the email has been sent out correctly. The email will contain the Test Subject subject, with a plaintext email body test payload and a test.txt attachment containing the text from /tmp/test.txt. If you attempt to reply to the email, the recipient of the composed email would be the address included in the Reply-To field, rather than the original sender (From address).

Out Ports

On Exception

The message will be sent to this out port if the Egress Connector failed to process the message due to some reason

Side Ports

Connector Operation

This port is used to connect operational elements to the Egress Connector. By default, user does not have to connect any operational element and the default connector operation will be used.

Parameters

* marked fields are mandatory.

Protocol *

Transport

Protocol to be used for accessing the mail server. SMTP (smtp) is recommended.

Host *

Transport

Hostname (or IP address) of the mail server

Port *

Transport

Service port on the mail server (usually dependent on the protocol)

User *

Transport

Username for authenticating to the mail server

Password *

Transport

Password for authenticating to the mail server

Other Settings

Transport

Map of additional transport-level properties for mail server access, such as standard JavaMail properties (e.g. enabling SSL as in the above example)

From

Basic

From address for the outbound email

Reply-To

Basic

Reply-To address to be included in the outbound email

To

Basic

A comma-separated list of To addresses for the outbound email

CC

Basic

A comma-separated list of CC addresses for the outbound email

BCC

Basic

A comma-separated list of BCC addresses for the outbound email

Subject

Basic

Subject of the outbound email

Priority

Basic

Priority of the outbound email (may be email provider specific)

In this topic
In this topic
Contact Us