EMail Notification
Posted: Tue Nov 06, 2012 12:11 pm
Hi
I have written a TI process for enable TM1 to send confirmation emails after executing a chore if there is any error log found. I am using VBS script (down loaded) and made some additional changes. And calling this VBS inside the TI.
I don't know where I made mistake but it is not working as expected. Sending the notification to the admins but not attaching the multiple error files.
I think i am making mistake in the time stamp line but not sure. Any help. Thanks in advance.
Thank
kkmk
Prolog:
#****Begin: Generated Statements***
#****End: Generated Statements****
# set empty string as quote char
DatasourceASCIIQuoteCharacter = '';
# set filename
sFileName = 'C:\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:#999999;color:#FFFFFF;padding-left:5px;padding-right:5px;width:120px;"><strong>Notification
</stron
g></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 = '<br/><div class="footer" align="left">Notifications generated from TM1, provided by <br/><img src="http://nnorsovmas082/site_logo.png" width=
"80"/></div>';
AsciiOutput ( sFileName, sHtml );
sHtml = '</body></html>';
AsciiOutput ( sFileName, sHtml );
#**************************************************************************************************************************************
#Setup Variables
Lastfile = '';
alllogs = '';
# Find todays date
s_TimeStamp = TimSt (Now, '\Y\m\d');
# Search the logs dir for last file
logfile = WildcardFileSearch( 'C:\Logs\TM1ProcessError_'|s_TimeStamp|' *.log', '');
ASCIIOUTPUT('c:\debug.txt' , logfile);
WHILE ( logfile @<> '' );
logname = 'C:\Logs\' | logfile;
alllogs = logname | ' ; ' | alllogs;
Lastfile = logfile;
logfile = WildcardFileSearch( 'C:\Logs\TM1ProcessError_'|s_TimeStamp|'*.log', '');
END;
# set filename
pAttachFile = alllogs;
EPILOG
#****Begin: Generated Statements***
#****End: Generated Statements****
sSender = 'sample@domain.com';
sSMTPSvr = 'exchgdomain.com';
IF( pAttachFile @<> '' );
arguments = 'CScript C:\sendMailOther.vbs '|sSMTPSvr |' ' | sSender | ' "'|pRecipient|'" "'|pSubject|'" "'
| sFileName | '" "' | alllogs | '"';
ELSE;
arguments = 'CScript C:\sendMailOther.vbs '|sSMTPSvr |' ' | sSender | ' "'|pRecipient|'" "'|pSubject|'" "'
| sFileName | '"' ;
ENDIF;
EXECUTECOMMAND(arguments ,1);
ASCIIOUTPUT('debug.csv',arguments);
SendMailOther.VBS
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/config ... /sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/config ... smtpserver") = SMTPServer
.Update
End With
With iMsg
Set .Configuration = iConf
.To = Mail_to
.From = Mail_from
.Subject = Subject
.HTMLBody = readFile(Body)
if Attach <> "" then
a= Split(Attach, ";")
for each x in a
.AddAttachment x
next
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
I have written a TI process for enable TM1 to send confirmation emails after executing a chore if there is any error log found. I am using VBS script (down loaded) and made some additional changes. And calling this VBS inside the TI.
I don't know where I made mistake but it is not working as expected. Sending the notification to the admins but not attaching the multiple error files.
I think i am making mistake in the time stamp line but not sure. Any help. Thanks in advance.
Thank
kkmk
Prolog:
#****Begin: Generated Statements***
#****End: Generated Statements****
# set empty string as quote char
DatasourceASCIIQuoteCharacter = '';
# set filename
sFileName = 'C:\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:#999999;color:#FFFFFF;padding-left:5px;padding-right:5px;width:120px;"><strong>Notification
</stron
g></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 = '<br/><div class="footer" align="left">Notifications generated from TM1, provided by <br/><img src="http://nnorsovmas082/site_logo.png" width=
"80"/></div>';
AsciiOutput ( sFileName, sHtml );
sHtml = '</body></html>';
AsciiOutput ( sFileName, sHtml );
#**************************************************************************************************************************************
#Setup Variables
Lastfile = '';
alllogs = '';
# Find todays date
s_TimeStamp = TimSt (Now, '\Y\m\d');
# Search the logs dir for last file
logfile = WildcardFileSearch( 'C:\Logs\TM1ProcessError_'|s_TimeStamp|' *.log', '');
ASCIIOUTPUT('c:\debug.txt' , logfile);
WHILE ( logfile @<> '' );
logname = 'C:\Logs\' | logfile;
alllogs = logname | ' ; ' | alllogs;
Lastfile = logfile;
logfile = WildcardFileSearch( 'C:\Logs\TM1ProcessError_'|s_TimeStamp|'*.log', '');
END;
# set filename
pAttachFile = alllogs;
EPILOG
#****Begin: Generated Statements***
#****End: Generated Statements****
sSender = 'sample@domain.com';
sSMTPSvr = 'exchgdomain.com';
IF( pAttachFile @<> '' );
arguments = 'CScript C:\sendMailOther.vbs '|sSMTPSvr |' ' | sSender | ' "'|pRecipient|'" "'|pSubject|'" "'
| sFileName | '" "' | alllogs | '"';
ELSE;
arguments = 'CScript C:\sendMailOther.vbs '|sSMTPSvr |' ' | sSender | ' "'|pRecipient|'" "'|pSubject|'" "'
| sFileName | '"' ;
ENDIF;
EXECUTECOMMAND(arguments ,1);
ASCIIOUTPUT('debug.csv',arguments);
SendMailOther.VBS
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/config ... /sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/config ... smtpserver") = SMTPServer
.Update
End With
With iMsg
Set .Configuration = iConf
.To = Mail_to
.From = Mail_from
.Subject = Subject
.HTMLBody = readFile(Body)
if Attach <> "" then
a= Split(Attach, ";")
for each x in a
.AddAttachment x
next
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