Qlik Community

QlikView Documents

Documents for QlikView related information.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More

Sending email from Qlikview

Not applicable

Sending email from Qlikview

Hi,

Sometimes we need to send objects by email.

Well, i solved this 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.

Macro.png

SendEmail.png

To execute Powershell from Qlikview Script, call this 'execute'

Execute cmd /C powershell -command  c:\temp\enviar_email_correto.ps1;

That´s all folks

João

Tags (1)
Comments
Not applicable

Hi,

great post, very useful in the corporate environment among many other utilities

Luminary
Luminary

Thank you for your contribution João.

Setting up a powershell script to send an email is much easier compared to vb script using cdo objects.

Best Regards,

Pablo Labbe

Partner
Partner

Parabéns João. Parece uma ótima solução (como só tem brasileiro, vou de português mesmo). Hehehe.

nareshthavidishetty
Contributor III

How to and where to write this script.

0 Likes

Nice, If you can provide the full application in WRAR file. It would be great helpful !!!

0 Likes
keerthika
Contributor II

Where i have to write a powershell script

0 Likes
Version history
Revision #:
1 of 1
Last update:
‎2015-01-30 02:43 PM
Updated by: