A site about Talend
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.
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.
We'll start off by creating a new Job and adding a tSendMail component.
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.
As previously discussed, the tSendMail component has quite a few configuration options, as can be seen from the following screenshot.
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.
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
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";
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]comments powered by Disqus