Expert Consultancy from Yellow Pelican

tSendMail

A site about Talend

tSendMail Component

The tSendMail component is part of the Internet family of components and allows you to send Email directly from your Job using the Simple Mail Transfer Protocol (SMTP).

tSendMail is a highly configurable component. I usually recommend using Context Variables to configure all components, providing for ease of maintenance, reusability and ease of promoting your Jobs through development, test, and production. I will demonstrate this in this tutorial on tSendMail, although you may choose to skip this part if you wish.

Third Party Java Libraries

tSendMail is dependent on some third party Java libraries. In older versions of Talend, many libraries were included; however, in more recent versions, this has changed, probably due to licensing constraints. If you're using a more recent version of Talend, some additional libraries will need to be installed before you can use the tSendMail component. Luckily, Talend Studio deals with this for you.

Gmail

For this tutorial, we'll use Gmail to both send and receive our emails. For additional information on using the Gmail SMTP server, read this article on Gmail Settings.

Getting Started

We'll start off by creating a new Job and adding a tSendMail component.

Image 1


Downloading Required Third Party Libraries

We'll now select the Component Tab. If any Third Party Libraries are required, we will have the option to download them now. If you are not required to download any libraries, simply continue to the next step.

Image 2


Hit the Install... button and follow the instructions. in the case of my own current set-up, I needed to install the JavaBeans Activation Framework (activation.jar) and JavaMail (mail-1.4.jar).

Configuring tSendMail

As previously discussed, the tSendMail component has quite a few configuration options, as can be seen from the following screenshot.

Image 3


tSendMail Context Group

We're going to configure it using a Context Group. Generally speaking you can usually only configure text values using Context Variables; unless the component supports Dynamic settings. Unfortunately, I've only found one of the standard components that actually does; which is a real shame. We'll discuss the use of Dynamic settings in a later article.

If you choose not to use a Context Group for this tutorial, you may ignore the sections that discuss Context and simply use literal values in the component's configuration; however, I would strongly recommend using Context for all component configuration.

Create a new Context Group named SendMail and add a String variable for each value. The variable name should be prefixed with sendMail, for example, sendMailTo.

You should now have a Context Group that looks something like the screenshot below. Note that SendMailSMTPPort must be defined as a String value even though you will be passing an integer value.

Image 4


Setting Values

Now that your new Context Group has been created, you can add this to your Job. You can do this by simply dragging the Context Group to the Job Designer panel. Now add a tJava component and create assignments that are similar to those shown below. If you're using a different SMTP server, then amend the settings accordingly. Connect tJava to tSendMail using the trigger OnJobjobOk.

Note. Ideally, you will be externalising these settings rather than hard-coding then in your Job. For the purposes of this tutorial, this is good enough. There are many ways that you can externalise your Context. My preference is to use a Child Job as described in the article LibContextReader.

context.sendMailTo="Email1@talendbyexample6.com,Email2@talendbyexample6.com";
context.sendMailFrom="Email3x4wq@gmail.com";
context.sendMailSendername="Talend By Example";
context.sendMailCc=null;
context.sendMailBcc=null;
context.sendMailSubject="This is a test email from Talend Data Integration";
context.sendMailMessage="You can send an Email from Talend Data Integration using any SMTP server.";
context.sendMailSMTPHost="smtp.gmail.com";
context.sendMailSMTPPort="465";
context.sendMailUsername="Email3x4wq@gmail.com";
context.sendMailPassword="YourPasswordGoesHere";


Edit tSendMail Settings

We'll now configure tSendMail using our Context Variables, as shown below. Note that Gmail requires SSL, and this must be configured manually as it cannot be dynamically set.

Image 5


Conclusion

You have now created a Talend Job that is capable of sending an Email using an Simple Mail Transfer Protocol (SMTP) server. Your Job should look similar to the screenshot shown below.

Image 6


You may now run your Job. If everything is configured correctly, your Job will run successfully and your Email will be delivered.

Starting job SendMail at 08:54 09/11/2014.

[statistics] connecting to socket on port 3498
[statistics] connected
[statistics] disconnected
Job SendMail ended at 08:55 09/11/2014. [exit code=0]




Expert Consultancy from Yellow Pelican
comments powered by Disqus

© www.TalendByExample.com