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&"<Td><font face=""verdana"" size=""1"">"
      txtBody=txtBody&" </font></Td>"
      txtBody=txtBody&"<Td bgcolor="&Report_Table.GetCell(i,2).text &"><font face=""verdana"" size=""1"">"
      txtBody=txtBody&" </font></Td>"
      txtBody=txtBody&"</TABLE> </BODY></HTML>"
      Set gObjExcel=Nothing
      Set objMsg = CreateObject("CDO.Message")
      Set msgConf = CreateObject("CDO.Configuration")
      ' Server Configuration
      msgConf.Fields.Item("") = 2 
      msgConf.Fields.Item("") = "smpthost" 
      msgConf.Fields.Item("") = 25 
      msgConf.Fields.Item("") = 1 
      ' Email
      objMsg.Subject = "Design and Planning Report"
      'objMsg.To = "" 
      objMsg.Bcc= var_emailRecipients
      objMsg.From = "" 
      'assign body to the message
      objMsg.HTMLBody =txtBody
      Set objMsg.Configuration = msgConf
      Msgbox("Report has been mailed.")
      ' Clear objects
      Set objMsg = nothing
      Set msgConf = nothing
    end sub