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