How to Send email from Qlikview | Interview questions

How to Send email from Qlikview?

Solution:
Hi,
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.gmail.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$body = 'Image and text<br /><img src="cid:att" />'
$msg = new-object Net.Mail.MailMessage
$msg.From ="name@domain.com.br"
$msg.To.Add("name@domain.com")
$msg.Subject = 'Text, Image and CC from powershell'
$msg.Body = $body
$msg.IsBodyHTML = $true
$msg.Attachments.Add($att)
$smtp.Send($msg)
$att.Dispose()
 
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
  ActiveDocument.GetApplication.WaitForIdle
  ActiveDocument.GetSheetByID("DASH").Activate
  vFolder = ActiveDocument.GetVariable("c:\temp\").GetContent().String
  set obj = ActiveDocument.GetSheetObject("EXPORT")
  ActiveDocument.GetApplication.WaitForIdle
  fileName = "imagem.jpg"
  ActiveDocument.GetApplication.WaitForIdle
  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)

Comments

Archive

Contact Form

Send