Thursday 26 January 2017

How to send a Email with attachments in SAP BODS

This is one of the draw back in data services, because we dont have in built feature for sending emails with attachments.

To solve this issue, We have to write a VB script

Step 1):- Open the notepad then Copy the below code and paste in notepad

strSMTPFrom = "prasad@gmail."
strSMTPTo = "prasad@gmail.com"
strSMTPRelay = "SMTPOUT.YOURCOMAPNY.COM"
strHTMLBody = " <HTML><BODY><font size=3>Hello Team,<BR><BR>HELLOOOOOOOOOOOOOOO. <BR><BR> Regards' <BR>Team</font></BODY>"
strSubject = "PFA"
strAttachment = "\\\\D:\\FILEPATH.CSV"
Set oMessage = CreateObject("CDO.Message")
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPRelay
oMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
oMessage.Configuration.Fields.Update
oMessage.Subject = strSubject
oMessage.From = strSMTPFrom
oMessage.To = strSMTPTo
oMessage.HTMLBody = strHTMLBody
oMessage.AddAttachment strAttachment
oMessage.Send


2) then save as filename.VBS
3) After that go to script and add the below command

$L_ORACLE= 'SELECT UPPER(sys_context(\'userenv\',\'instance_name\')) FROM DUAL'; 
$L_DATABASE = sql('DS_DATASERVICES',$L_ORACLE);

$G_V1 = cast(sql('DS_DATASERVICES','(select COUNT(1) FROM TABLE)'),'INT');


IF ($G_V1 >=1 and $L_DATABASE='DEV')
BEGIN
 
 exec('CScript','\\\\FILEPATH\\FILE_DEV.vbs', 8);
 
 END 

ELSE IF ($G_V1>=1 and $L_DATABASE='QA')
BEGIN
exec('CScript','\\\\FILEPATH\\FILE_QA.vbs', 8);
END 

ELSE IF ($G_V1>=1 and $L_DATABASE='PROD')
BEGIN
exec('CScript','\\\\FILEPATH\\FILE_PROD.vbs', 8);
END

 ELSE

 BEGIN
 PRINT ('No Data found In DATABASE');
 END