Send email with attachment

Hello Guys,

            I have a DS job which at the end run couple of validations and store the records which fail the validation inside CSV file.

My ques: Is there a way to automate a process to send this CSV as an attachment and email it to my user?

Guru’s pl help

Thanks


DSallday (BOB member since 2012-10-03)

Here it goes

VB Script:


Set objMessage = CreateObject("CDO.Message")
objMessage.From 		= WScript.Arguments(0)
objMessage.To 			= WScript.Arguments(1)
objMessage.Cc 			= WScript.Arguments(2)
objMessage.Bcc 			= WScript.Arguments(3)
objMessage.Subject 		= WScript.Arguments(4)
objMessage.TextBody 		= WScript.Arguments(5) & vbcrlf
objMessage.AddAttachment 	  WScript.Arguments(6)


'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.

	objMessage.Configuration.Fields.Item _
	("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
	objMessage.Configuration.Fields.Item _
	("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP_SERVER_NAME"

'Server port (typically 25)
	objMessage.Configuration.Fields.Item _
	("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

	objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==

	objMessage.Send

Save the above as a .vbs file

Courtesy: Google & Internet 8)

Calling in DS:


EXEC('CSCRIPT.EXE','[$G_VBS_SCRIPT_FILE] "[$G_EMAIL_FROM]" "[$G_EMAIL_TO]" "[$G_EMAIL_CC]" "[$G_EMAIL_BCC]" "[$G_EMAIL_SUBJECT]" "[$G_EMAIL_BODY]" "[$G_EMAIL_ATTACHMENT]"',8);

This call from DS is a smaller version. I have actually wrapped this in a custom function and made some checks for input…

That VB code is very very very basic. It can’t handle errors or write log or something.


ganeshxp :us: (BOB member since 2008-07-17)

I have a client that is (successfully) using the BLAT command line utility to send email and attachments using SMTP. I think it was approved by the IT departments security group. The VB option may not have been approved if they had tried that. Don’t know for sure.


eganjp :us: (BOB member since 2007-09-12)

hey Ganesh,

code is working fine when manually executing script, but when called from DS no result and error :crazy_face:

any clue?

Thanks.


n78882 :us: (BOB member since 2010-09-17)

manually executed from command prompt? if so on the job server box’s command prompt or on your local machine? Did you used 8 as the flag? Flag 8 should say the Standard Error


ganeshxp :us: (BOB member since 2008-07-17)

it worked -" " was missing in script path
thanks

EXEC(‘CSCRIPT.EXE’,’"[$G_VBS_SCRIPT_FILE]" “[$G_EMAIL_FROM]” “[$G_EMAIL_TO]” “[$G_EMAIL_CC]” “[$G_EMAIL_BCC]” “[$G_EMAIL_SUBJECT]” “[$G_EMAIL_BODY]” “[$G_EMAIL_ATTACHMENT]”’,8 );


n78882 :us: (BOB member since 2010-09-17)

Ohhh got you! I just copy-pasted the piece I used inside the function…

My bad! :yesnod:


ganeshxp :us: (BOB member since 2008-07-17)

Hi Ganesh
I am using the same script but i facing the following error

There is no script engine for file extension “.com”.

Can please rply me where i am doing wrong or is their any alternative to test it manually

I do have only developer access.

Thanks


srmkumar (BOB member since 2013-03-19)

Looks much of a Scripting issue? Are you doing this on a Windows Server box or just on a local Win7/WinXP…etc?


ganeshxp :us: (BOB member since 2008-07-17)

You may use Unix command from a DS script to send email as an attachment if you are using Unix server.

Mailx and UUencode command can be useful .


kgecdeep (BOB member since 2012-07-25)

Much easier way is to use some third party tools, such as SENDMAIL. you don’t need o install, just download, and execute the file SENDMAIL.exe from command line.


amuh10 :uk: (BOB member since 2012-04-11)

Does anyone know what would be the syntax for calling vb script on linux environment?