Qlik Community

QlikView App Dev

Discussion Board for collaboration related to QlikView App Development.

Announcements
Now Live: Qlik Sense SaaS Simplified Authoring – Analytics Creation for Everyone: READ DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Send Chart in body using CDO.Message

Hi All,

I am trying to automate sending a daily email using vbscript that contains one chart in the body of the email.  I have it working great locally where I can use Outlook by using:

sub DailyMailLocal

  Set myOutlook = CreateObject ("Outlook.Application")

  Set myMessage = myOutlook.CreateItem(olMailItem)

  myMessage.BodyFormat = 2 'HTMLFormat

  myMessage.To = "testemailaddress@host.com"

  myMessage.Subject = "Qlikview Email Testing"

  Set myInspector = myMessage.GetInspector

  Set myDoc = myInspector.WordEditor

  myInspector.WordEditor.Content.InsertBefore chr(13)

  ActiveDocument.GetSheetObject("CH154").CopyTableToClipboard TRUE

  myDoc.Range(1,1).Paste

  myInspector.WordEditor.Content.InsertAfter chr(13)

  myMessage.Display

  Set myMessage = Nothing

  Set myApp = Nothing

  Set myInspector = Nothing

  Set myDoc = Nothing

end sub

How can this be recreated using CDO.Message?  I have the below working where the excel file is attached to the message.  But what I require is the above result with the chart as HTML body in the email.

Sub DailyMailServer

  Set obj = ActiveDocument.GetSheetObject("CH154")

  obj.ExportEx "C:\Users\vercillo\Documents\Temp.htm",5

  Set myMail = CreateObject("CDO.Message")

  myMail.Subject = "QlikView Email Testing"

  myMail.From = "testemailaddress@host.com"

  myMail.To = "testemailaddress@host.com"

  myMail.AddRelatedBodyPart "C:\Users\vercillo\Documents\Temp.xls", "Temp.xls", 0

  myMail.Configuration.Fields.Item _

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

  myMail.Configuration.Fields.Item _

  ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 0

  myMail.Configuration.Fields.Item _

  ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailhost.test.com"

  myMail.Configuration.Fields.Item _

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

  myMail.Configuration.Fields.Update

  myMail.Send

  set myMail = nothing

  set  obj = nothing

End Sub

Any help is greatly appreciated, and I hope these working code snips might help someone!

1 Solution

Accepted Solutions
vikasmahajan

Hii,

set cs = ActiveDocument.GetSheetObject("CH663")

cs.ExportHtml "d:\tmp\sales.html"

objEmail.CreateMHTMLBody "file://d:\tmp\sales.html"

Should work for you.

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution.
If you want to go quickly, go alone. If you want to go far, go together.

View solution in original post

7 Replies
gainkarthi
Partner - Specialist
Partner - Specialist

You got any improvement in this?

Not applicable
Author

No, I ended up going with the less than ideal file as an attachment option.

vikasmahajan

Hii,

set cs = ActiveDocument.GetSheetObject("CH663")

cs.ExportHtml "d:\tmp\sales.html"

objEmail.CreateMHTMLBody "file://d:\tmp\sales.html"

Should work for you.

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution.
If you want to go quickly, go alone. If you want to go far, go together.
Not applicable
Author

Thank you Vikas, sorry for the delayed response... but this worked beautifully!

vikasmahajan

No Problem ,WelCome

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution.
If you want to go quickly, go alone. If you want to go far, go together.
nesawant
Contributor II
Contributor II

Hi Vikas,

How do I do this for multiple objects?

So my requirement is to send multiple charts in email body. I even tried copying sheet with all these charts in mail body but that doesn't work. Any idea?

Best Regards,

Neha

vikasmahajan

you embedded the charts in message body if 2 or 3  but it is advised that create a pdf and attached with message send it to user.

Vikas

Hope this resolve your issue.
If the issue is solved please mark the answer with Accept as Solution.
If you want to go quickly, go alone. If you want to go far, go together.