How to Send email from Qlikview | Interview questions

How to Send email from Qlikview?

Sometimes we need to send objects by email.
Well, is the solution of this problem using Powershell and Qlikview, like this.
1. Script Powershell: (Save this script on email.ps1)
$att = new-object Net.Mail.Attachment("C:\temp\imagem.jpg")
$att.ContentId = "att"
$smtpServer = ""
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$body = 'Image and text<br /><img src="cid:att" />'
$msg = new-object Net.Mail.MailMessage
$msg.From =""
$msg.Subject = 'Text, Image and CC from powershell'
$msg.Body = $body
$msg.IsBodyHTML = $true
Well, we really can improve this script checking if there is an image on path, or even using credentials to turn this script safer. But 'now()', this is enough. ;-)
2. Macro to save images:
public function ExportImage
  vFolder = ActiveDocument.GetVariable("c:\temp\").GetContent().String
  set obj = ActiveDocument.GetSheetObject("EXPORT")
  fileName = "imagem.jpg"
  obj.ExportBitmapToFile vFolder & fileName
end function
3. To send message:
Create a button and assign two triggers:
3.1 Run a macro to save images
3.2 Set an event 'Set' that will run Powershell script.

To execute Powershell from Qlikview Script, call this 'execute'
Execute cmd /C powershell -command  c:\temp\enviar_email_correto.ps1;

Reference/Credit of this article goes to : Joao Gutheil (Qulik Community)

Post a Comment

* Please Don't Spam Here. All the Comments are Reviewed by Admin.