Sending html email using TI

Post Reply
Bean123
Posts: 2
Joined: Mon Jul 06, 2020 8:48 am
OLAP Product: 2.0.9.1
Version: 2.0.9.1
Excel Version: 2016

Sending html email using TI

Post by Bean123 »

I would like to insert HTML into an email message using TI? For example, inserting 2 tables and details as well.
How do i do that?
HighKeys
Posts: 117
Joined: Fri Aug 09, 2019 10:11 am
OLAP Product: TM1 / TM1 Web / Perspectives
Version: Planning Analytics V2.0.9
Excel Version: Office 365

Re: Sending html email using TI

Post by HighKeys »

Hi,

somwhere from the Forum here..


You have to edit the HTML code inside the TI, the E-mail was sent over SMTP via VBS.

Prolog:

Code: Select all

  # set empty string as quote char
  DatasourceASCIIQuoteCharacter = '';

  # set filename
  sFileName = 'D:\Planning_Analytics\Extra_Scripts\send.txt';


  # header
  sHtml = '<html><head><style>.footer {font-size:11px;}; body {font-family: Calibri;font-size:11px;}</style></head><body>';
  AsciiOutput ( sFileName, sHtml );


  sHtml = '<table width="100%" cellspacing="0" style="border:1px solid #000000;font-size:11px;">';
  AsciiOutput ( sFileName, sHtml );

  sHtml = '<tr><td valign="middle" style="background-color:#00497b;color:#FFFFFF;padding-left:5px;padding-right:5px;width:120px;height:50px;"><strong>Benachrichtigung: ' | pTitle | '</strong></td>';
  AsciiOutput ( sFileName, sHtml );

  sHtml = '</tr>';
  AsciiOutput ( sFileName, sHtml );

sColor = '#EEEEEE';

sHtml = '<tr style="background-color:' | sColor | ';"><td valign="middle" style="vertical-align:top;padding-left:5px;padding-right:5px;">' | pBody | '
</td>';
AsciiOutput ( sFileName, sHtml );

sHtml = '</tr>';
AsciiOutput ( sFileName, sHtml );

sHtml = '</table>';
AsciiOutput ( sFileName, sHtml );

sHtml = '</body></html>';
AsciiOutput ( sFileName, sHtml );


Epilog:

Code: Select all

sSender = '"email@domain.com"';
sSMTPSvr = '"smtpserver.net"';

IF( pAttachFile @<> '' );
arguments = 'CScript [b]PATH[/b]\sendMailOther.vbs '|sSMTPSvr |' ' | sSender | ' "'|pRecipient|'" "'|pSubject|'" "'
| sFileName | '" "' | pAttachFile | '"';
ELSE;
arguments = 'CScript [b]PATH[/b]\sendMailOther.vbs '|sSMTPSvr |' ' | sSender | ' "'|pRecipient|'" "'|pSubject|'" "'
| sFileName | '"' ;
ENDIF;


And this is the "sendMailOther.vbs" script:

Code: Select all


Dim SMTPServer
Dim SMTPPort
Dim Mail_from
Dim Mail_to
Dim Subject
Dim Body
Dim Attach

SMTPServer = WScript.Arguments(0)
Mail_from = WScript.Arguments(1)
Mail_to = WScript.Arguments(2)
Subject = WScript.Arguments(3)
Body= WScript.Arguments(4)
if WScript.Arguments.Count = 6 then
  Attach= WScript.Arguments(5)
end if

set imsg = createobject("cdo.message")
set iconf = createobject("cdo.configuration")

Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer
.Update
End With

With iMsg
    Set .Configuration = iConf
        .To = Mail_to
        .From = Mail_from
        .Subject = Subject
        .HTMLBody = readFile(Body)
        if Attach <> "" then
        	.AddAttachment Attach
        end if
        .fields.update
        .Send
End With

set imsg = nothing
set iconf = nothing


function readFile(sPath) 
    const forReading = 1 
    dim objFSO, objFile, sData 
    set objFSO = createobject("Scripting.FileSystemObject") 
    set objFile = objFSO.openTextFile(sPath, ForReading) 
    sData = "" 
    do until objFile.atEndOfStream 
        sData = sData & objFile.readLine & vbCrLf 
    loop 
    objFile.close 
    set objFile = nothing 
    set objFSO = nothing 
    readFile = sData 
end function



Hope it helps!

BR
Post Reply