Tabelau and Email
From time to time I need to send a report to someone without the tableau online licence. If for any reason you have to do it daily this manual task can quickly become a burden.
Luckily there is a (limited) way to automate it with a bit of scripting. It gives an option of sending a pdf, png, csv for views and workbooks (not recommended from the security point of view – especially if your data is sensitive!!). A Windows box is needed for this – which is not ideal.
The first step is to download and install the tabcmd tool.
The next step is to script everything using your favourite scripting language. I went with PowerShell as this must be run on Windows. Here is a proof of concept script that does the absolute minimum:
# Clean the old report
If (Test-Path C:\pstmp\report_file.csv){
Remove-Item C:\pstmp\report_file.csv
}
# Set up a connection to Tableau Online
$command = @'
cmd.exe /C "C:\Program Files\Tableau\Tableau Server\9.0\extras\Command Line Utility\tabcmd.exe" login -s http://10ay.online.tableau.com/ -u USER -p PASSS
'@
Invoke-Expression -Command:$command
## Refresh and pull report
$command2 = @'
cmd.exe /C "C:\Program Files\Tableau\Tableau Server\9.0\extras\Command Line Utility\tabcmd.exe" get /views/path_toview/view_name.csv?:refresh=yes -f C:\pstmp\report_file.csv
'@
Invoke-Expression -Command:$command2
## Email credential
$pwd = ConvertTo-SecureString ‘PASSS’ -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential [email protected],$pwd
## Send the email
$param = @{
SmtpServer = 'smtp details'
Port = 587
Credential = $cred
UseSSL = $true
From = '[email protected]'
To = @('[email protected]';'[email protected]')
Subject = 'Blog daily report'
Body = "Blog daily"
Attachments = 'C:\pstmp\report_file.csv'
}
Send-MailMessage @param
Please note that this is just a PoC. Please be advised that storing username/password in a script is a security issue. Also, it’s a good idea to create a generic email address just for this purpose rather than sending it from your personal one.
Finally you will find is more documentation about tabcmd here.