Qlik Community

QlikView Documents

Documents for QlikView related information.

Send Mail from QlikView with table in the mail body

cabhijit
Valued Contributor

Send Mail from QlikView with table in the mail body

Lot of material is available on the forum showing how to send mail from QlikView.

In this post, I'm going to show how we can send mail from QlikView with formatted mail body.

Below script shows the example, where sheet object is embedded within the mail body:

sub SendMail

  set Report_Table=ActiveDocument.GetSheetObject("Report_Table")

  ' Get Email recipient list stored in the varable vEmailRecipients

  var_emailRecipients = ActiveDocument.Variables("vEmailRecipients").GetContent.string

  'msgbox var_emailRecipients

  'format the mail body

  txtBody="<HTML><BODY><font face=""verdana"" size=""1""> Design and Planning Report <br> <br>"

  txtBody=txtBody & "<TABLE border=""1"">"

  For i=0 to Report_Table.GetNOOfRows

  txtBody=txtBody&"<TR>"

  txtBody=txtBody&"<Td><font face=""verdana"" size=""1"">"

  txtBody=txtBody&Report_Table.GetCell(i,0).text

  txtBody=txtBody&" </font></Td>"

  txtBody=txtBody&"<Td bgcolor="&Report_Table.GetCell(i,2).text &"><font face=""verdana"" size=""1"">"

  txtBody=txtBody&Report_Table.GetCell(i,1).text

  txtBody=txtBody&" </font></Td>"

  txtBody=txtBody&"</TR>"

  Next

  txtBody=txtBody&"</TABLE> </BODY></HTML>"

  Set gObjExcel=Nothing

  Set objMsg = CreateObject("CDO.Message")

  Set msgConf = CreateObject("CDO.Configuration")

  ' Server Configuration

  msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

  msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smpthost"

  msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

  msgConf.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

  msgConf.Fields.Update

  ' Email

  objMsg.Subject = "Design and Planning Report"

  'objMsg.To = "testmail@domain.com"

  objMsg.Bcc= var_emailRecipients

  objMsg.From = "apptechsupport@domain.com"

  'assign body to the message

  objMsg.HTMLBody =txtBody

  Set objMsg.Configuration = msgConf

  objMsg.Send

  Msgbox("Report has been mailed.")

  ' Clear objects

  Set objMsg = nothing

  Set msgConf = nothing

end sub

Labels (2)
Comments
preminqlik
Valued Contributor II

hi , am getting error in 16th line fr your code.

please attach sample

thanks

cabhijit
Valued Contributor

Sample file will have the same macro code which I've mentioned here.

Can you tell me which error you are getting?

sayadutt
New Contributor II

even I amgetting error on line 16.

For i=0 to Report_Table.GetNOOfRows

Error:

Object required: 'Report_Table'

Please suggest

cabhijit
Valued Contributor

This error is because you don't have any object on the sheet with id 'Report_Table'.

Either give the id of your table in GetSheetObject or change id of your table to 'Report_Table'.

sayadutt
New Contributor II

Hi Abhijit,

Now I am not getting that error as I am using the ID.

Can you please suggest whether this macro will work in Outlook 2010? I am using Outlook 2010 and getting the following error.

When I checked the internet, this is what I got

https://support.microsoft.com/en-us/kb/2028411

Error I am getting:

The transport failed to connect to the server.

Please suggest. Can we use it in Outlook 2010?

Not applicable

This can be done with native QlikView NPrinting software without the need for macros or coding:

Introducing QlikView NPrinting | Qlik

nadeemsmarty
Contributor II

But that requires additional costs which organisations do not necessarily want

cabhijit
Valued Contributor

sayadutt

This code doesn't have to anything with outlook. It can send mail to any type of inbox.Have you configured SMTP details correctly like SMTP host,Port number etc?

cabhijit
Valued Contributor

Thank for mentioning here. Yes, NPrinting is a great tool to create customized reports of QlikView if you are ready to bare the cost of additional licence.

Here is an alternatively approach: Re: Exportar varias tablas a un archivo html

- Marcus

Version history
Revision #:
1 of 1
Last update:
‎02-13-2015 04:53 AM
Updated by: