FOR BI PROS Tableau
Sending Emails with attachments from Tabcmd
September 8, 2015
0
, , , , , , ,
Spot the sendmail command

Spot the sendmail command

TabCmd is nice: you can logon to your server and generate fancy images and PDFs from your favorite workbooks. But sometimes you’d like to automate the flow and send emails to you or your users. No issues just check Tableau’s knowledge base article on tabcmd (Using Tabcmd). Oh, wait, it says:

“While the tabcmd by itself cannot send email messages”

Hmm, baad. Why would you install a third party small utility to send emails if you can just “fix” this gap by implementing a standard email sending command? Yes, tabcmd cannot send email messages “out-of-the-box”, but you can always make it smarter. Let me show in this post how can you add new functionality to tabcmd like sending emails.

Implementation

The goal is to be able to send a file from file system to a list recipients (like send a pdf file which was just downloaded with the very same tabcmd tool). So what we need to achieve our goal?

Tabcmd is a simple java application using a few open source and tableau specific java libraries. If you want to add your new command to tabcmd, you should create a java class which implements the com.tableausoftware.tabcmd.commands.Command  interface and put under app-tabcmd-latest-jar.jar‘s com/tableausoftware/tabcmd/commands directory (remember, jar is just a zip file). Simple.

Create command line options parser for your command

To add your command line options (extend the default set of command options) you should return with an apache-commons-cli’s Options object which will help parsing your parameters during run time:

Implement Metadata

You need also a few description method in your class. The basic String methods are getName(), getShortDescription(), getDescription(), getUsage(). If you don’t want to use http connection to tableau then also implement needsSession() and return with false.

Implement your business logic

During execution tabcmd will call the function execute  with all command line parameters (in parsed form).

As you see the commandLine object is ready to use and it contains the command line parameters supplied by the user. If you do not need HTTP communication with the Tableau Server (needsSession == false) just return with null.

You can check out the complete source of this implemented Command here.

For sending emails normally we should use com.tableausoftware.core.util.SMTPClient  but that one does not support attachments. No issues, let’s extend it!

  Getting it work

  Usage

To send email with file attachement use the following commmand line

The –smtp-user, –smtp-passw and –port command line options are optional.

The complete list of options can be obtained with tabcmd help sendmail .

Compile & Install

When compile include Tableau Server’s or tabcmd’s lib folder as classpath. After you are ready with the implementation just move the generated class file(s) into the app-tabcmd-latest-jar.jar package.

In practice, you need to copy the two class files into app-tabcmd-latest-jar.jar, located in the lib folder. I uploaded the binaries under releases as well. Download it and merge its contents with app-tabcmd-latest-jar.jar keeping the same directory names as it is in my zip file.

Sources & additional instructions are on the command’s github page: https://github.com/tfoldi/TabcmdSendEmail

Disclaimer

Code is absolutley unsupported and it has nothing to do with tableau software. Only publicly available interfaces were used from 3rd party libraries. No reverse engineering, no disassembling or anything like these where used to extend tabcmd.

Have fun!

 

Tamás Földi

Tamás Földi

Director of IT Development at Starschema
Decades of experience with data processing and state of the art programming. From nuclear bomb explosion simulation to distributed file systems. ethical hacking, real time stream processing practically I always had a great fun with those geeky ones and zeros.
Tamás Földi

Related items

/ You may check this items as well

Pasted image at 2018_01_09 04_59 PM

Python Experiments in Tableau 1. – Add live currency conversion to Tableau Dashboards using TabPy

TabCmd is nice: you can logon to your server and g...

Read more
Tableau Docker

HOWTO: Tableau Server Linux in Docker Container

TabCmd is nice: you can logon to your server and g...

Read more
Tableau Consistency Checker

Tableau Filestore Consistency Checker – How Repository Maps to Filestore

TabCmd is nice: you can logon to your server and g...

Read more