YADSSM (Yet another DS SendMail) question

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
cedua
Participant
Posts: 22
Joined: Mon Nov 10, 2008 1:21 pm

YADSSM (Yet another DS SendMail) question

Post by cedua »

Hi all there!

I have a job, and it checks if a file has something in it...
When the file is not empty, I use DSSendMail to (duh!) send an e-mail to someone....

But I like to know how I attach the file in the mail......

I have read a lot about it, and have read about the dssendmail_template.txt (I know where is it, etc etc)

I use the following command:

DSSendMail("From:DS@abc.com\nTo:abc1@abc.com,abc2@abc.com\nSubject:Test\nAttach:/dir/dir/file.txt\nBody:This is a test")

my job reports me the message "The following parameters in the call to DSSendMail were not mentioned in the file 'dssendmail_template.txt': attach"; but it sends the mail (without the attachment)

I know that I have to encode the file to use the sendmail (something like uuencode filename | /usr/sbin/sendmail -t.......) so I changed the template as follows:

Code: Select all

uuencode %attach% | /usr/sbin/sendmail -t <<////
From: %from%
To: %to%
Subject: %subject%

%body%
////
Can anyone help me about it? I feel it's a little what it's missing.....

Thx,

chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

What exact 7.x version are you running? Attachments were not supported until 'later', I think with 7.5. And you need to use the routine rather than the Notification Activity stage, yes?
-craig

"You can never have too many knives" -- Logan Nine Fingers
cedua
Participant
Posts: 22
Joined: Mon Nov 10, 2008 1:21 pm

Post by cedua »

Thx for replying,

7.0 (I know it, I know it....!!!)

So, It won't be possible this way....

I'm trying to do this from the "Job Control" (the job has no stages, I'm using only the job control to manage it....), so I wonder if I can do something like:

result = ExecSH("my_sendmail_sh")

The "my_sendmail_sh" would be something proper with de uuencode and sendmail stuff....
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Google for "sendmail uuencode attachment" to get the syntax needed. I used to use "mailx" in the past, found it a little more friendly but either should work.
-craig

"You can never have too many knives" -- Logan Nine Fingers
cedua
Participant
Posts: 22
Joined: Mon Nov 10, 2008 1:21 pm

Post by cedua »

Well, I have created a script to do this (google, another scripts, several RFC papers help me)

This is the script, use it if you want to.... (spanish used, it's my language)

Code: Select all

#!/usr/bin/sh
#################################################
# Este script manda correo a traves de sendmail #
# con attachment                               #
#################################################
# Recibe los siguientes parametros              #
# 1: Remitente                                  #
# 2: Destinatario                               #
# 3: Subject                                    #
# 4: Archivo a mandar                           #
#################################################
# Si se quiere poner un campo cc: se tiene que  #
# quitar el comentario correspondiente          #
#################################################
# TODO: que sean varios attachments             #
# idea: meter un ciclo for                      #
#################################################
(
echo "From: $1"
echo "To: $2"
#echo "CC: $CC"
echo "Subject: $3"
echo "Mime-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"JECS.boundary.Nov2009\""
Base=`basename $4`
echo "--JECS.boundary.Nov2009"
echo "Content-Type: text/plain; charset=ISO-8859-1; format=flowed"
echo "Content-Disposition: inline"
echo ""
echo "Esto es una prueba"
echo ""
echo "--JECS.boundary.Nov2009"
echo "Content-Type: text/plain; name=\"$Base\"; charset=US-ASCII"
echo "Content-Transfer-Encoding: uuencode"
echo ""
uuencode $4 $4
) | /usr/lib/sendmail -t
exit 0
Probed and it works just fine.

Now, I have a question I want to use this script calling it from the job control (it's a non stage job remember?) but I don't NEED to call it before-after the job. I need to call the script when the file (opened with OpenSeq) is NOT EMPTY.
Greetings,
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Then have your script check the file (perhaps using "test -s") and conditionally send the email if the file is non-empty.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

If you have already opened the file with OpenSeq, then the file size can be tested with the Status statement. This returns a dynamic array of information about the file - from memory, element #6 contains the file size.

Code: Select all

Status FileInformation From FileVariable
Then
   FileSize = FileInformation<6>
End
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
cedua
Participant
Posts: 22
Joined: Mon Nov 10, 2008 1:21 pm

Post by cedua »

The last script: (I'm working with this)

Code: Select all

#!/usr/bin/sh
#################################################
# Este script manda correo a traves de sendmail #
# con attachment                                #
################################################# 
# Recibe los siguientes parametros              #
# 1: Remitente                                  #
# 2: Destinatario                               #
# 3: Subject                                    #
# 4: Archivo a mandar                           #
# 5: Archivo original que se envio              #
# 6: RUTA FTP                                   #
#################################################
# Si se quiere poner un campo cc: se tiene que  #
# quitar el comentario correspondiente          #
#################################################
# TODO: que sean varios attachments             #
# idea: meter un ciclo for                      #
#################################################
if [[ -s $4 ]] ; then
  temp=`cat /DS_PROJ_DIR/files/FolioMaximo_Prov.txt | cut -c6-15`
  cuenta=`wc -l < $4`
  body="El archivo $5 se intento procesar con el folio $temp pero tiene $cuenta lineas con error"
  filename=`echo $5 | awk '{print substr($0,0,length($0)-5)}'`
  arch_status=$filename"2.TXT"
otro=`ftp -i -n << EOF
    open X.X.X.X
    user USER PASS
    cd /DIR/$6
    rename $5 $arch_status
    quit
EOF`
else
  temp=`cat /DS_PROJ_DIR/files/FolioMaximo_Prov.txt | cut -c6-15`
  body="El archivo $5 se proceso con el folio $temp y NO tiene registros con error"
  filename=`echo $5 | awk '{print substr($0,0,length($0)-5)}'`
  arch_status=$filename"3.TXT"
otro=`ftp -i -n << EOF
    open X.X.X.X
    user USER PASS
    cd /DIR/$6
    rename $5 $arch_status
    quit
EOF`
fi
(
echo "From: $1"
echo "To: $2"
#echo "CC: $CC"
echo "Subject: $3"
echo "Mime-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"JECS.boundary.Nov2009\""
Base=`basename $4`
echo "--JECS.boundary.Nov2009"
echo "Content-Type: text/plain; charset=ISO-8859-1; format=flowed" 
echo "Content-Disposition: inline" 
echo ""
echo "$body"
echo ""
echo "--JECS.boundary.Nov2009"
echo "Content-Type: text/plain; name=\"$Base\"; charset=US-ASCII"
echo "Content-Transfer-Encoding: uuencode"
echo ""
uuencode $4 $4
) | /usr/lib/sendmail -t
exit 0
I can explain it later (just in case you're wondering)

Greetings,
Post Reply