Link to home
Create AccountLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

Cannot send an e-mail out of ksh script

How  can I send an e-mail out of a ksh script with file attachment or with file contents (in html format) as a body of the e-mail?

I tried using

uuencode filename.html | mail -s  'Subject' user@example.com

But I get an error that it does not recognize uuencode or mail commands

This below didn't work either:

mail -s "Subject" user@example.com < filename.html

The error I get is

"SP2-0734: unknown command beginning &quot;mail -s &quot;T...&quot;"
Avatar of mgob
mgob
Flag of United States of America image

Check your environment variables and ensure that the location of both commands are in your path.  Or, set the full path to the command such as `/bin/mail` instead of just `mail`

( find the path with `which mail` and `which uuencode` )
Avatar of Nem Schlecht
Which OS (and version) are you running?

If it can't find uuencode *or* mail, I would want to think its a PATH problem.

You're second command didn't work because you were trying to run that at at Oracle prompt and not a UNIX prompt.
Avatar of YZlat

ASKER

I checked /usr/bin and both uuencode and mail are there

I ceched the PATH variable and it is as follows

/home/oracle:/usr/local/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/home/oracle/bin:/usr/bin/X11:/sbin:.:/u01/app/oracle/product/11.2.0.3/bin

Do you see anything that would prevent it from not finding mail or uuencode

I did try before running

/usr/bin/mail -s "Subject" user@email.com < myfile.html

but gotten the same error
For giggles/testing, try it with full paths:


/usr/bin/uuencode filename.html | /usr/bin/mail -s  'Subject' user@example.com
Avatar of YZlat

ASKER

that gave me

<p>
SP2-0734: unknown command beginning &quot;/usr/bin/m...&quot; - rest of line ignored.
<br>
SP2-0734: unknown command beginning &quot;/usr/bin/u...&quot; - rest of line ignored.
SOLUTION
Avatar of Nem Schlecht
Nem Schlecht
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of YZlat

ASKER

that's exactly what I do, I store the command in a ksh file and run it from the UNIX prompt
Avatar of YZlat

ASKER

actually running

mail -s "Subject" user@example.com < filename.html

from UNIX command prompt directly worked fine. Except the e-mail was plain text and not html. How can I make it in html format?

Also I need to run it from within the ksh script and not manually from the UNIX prompt
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
If it's a ksh script, you should be able to just cut/paste this into it.

What else does your ksh script do?  Does it do any Oracle stuff?
Avatar of YZlat

ASKER

yes, it retrieves data from oracle database, writes it to a fiel and then, supposedly sends this file over the e-mail
Avatar of YZlat

ASKER

Oh, I see! I probably need to exit from sqlplus in my ksh file first, before sending an e-mail
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of YZlat

ASKER

How can I exit Oracle CLI in my script?
Avatar of YZlat

ASKER

mail -a "Content-type: text/html" -s "Subject" user@example.com < filename.html

gave me an error: "mail: Not a recognized flag: a"
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of YZlat

ASKER

I tried using EXIT right before sending an e-mail but it loos like it exits the script altogether before even getting to the line that sends the e-mail
How are you running the sqlplus commands?  Try sending quit instead of exit.
Avatar of YZlat

ASKER

tried both, same result

I tried

exit;

exit
/

quit;

and

quit
/
Can you please post your full sqlplus section of your script? Or better yet the script in its entirety with anything sensitive removed?
Avatar of YZlat

ASKER

here is my code:

#!/usr/bin/ksh

export ORACLE_SID=DBName
ORAENV_ASK=NO
. oraenv
sqlplus -s /nolog <<EOF
CONNECT usr1/pwd
SET LINES 4000 TRIMS ON FEED OFF PAGES 0
SET MARKUP HTML ON SPOOL ON HEAD "<TITLE>SQL*Plus Report</title> -
<STYLE TYPE='TEXT/CSS'><!--BODY {background: ffffc6} --></STYLE>"
SET ECHO OFF
SPOOL myfile.html
SELECT * FROM my_view;
SPOOL OFF

exit;

mail -s "Subject" user@example.com < filename.html

Open in new window


if I remove eexit, I get an error, but if I leave the exit; there, it exits right after writing to the file
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
-a was *once* mailx only, but most standard OSes today have it on the standard 'mail' program.
Avatar of YZlat

ASKER

it worked sending the e-mail but it is still in text format. I am using AIX OS and -a does not seem to work. is there any other way?
Avatar of YZlat

ASKER

I tried using mailx command but got same error:

mailx: Not a recognized flag: a
Add the headers into your mail that I had posted above.
Avatar of YZlat

ASKER

where do I add those headers?
Avatar of YZlat

ASKER

I already have this in my html file

<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
Yea that's in the html file, but not in the mail headers, the easiest way to do this is to pipe it to mail with the headers already applied.

Put something like this at the top of that html file:

From: me@example.org
To: me@mail.com
Subject: MIME Test
Mime-Version: 1.0
Content-Type: text/html

Then punt that to mail with the -t flag like so:

cat filename.html | mail -t
Avatar of YZlat

ASKER

I can't really edit html file, it gets generated by sql plus
Avatar of YZlat

ASKER

Thanks for answering my original question. I will open new question for the rest
Okay so make a new file with it:

cat > ./outfile <<DELIM
From: me@example.org
To: me@mail.com
Subject: MIME Test
Mime-Version: 1.0
Content-Type: text/html
DELIM

cat filename.html >> outfile

cat outfile | mail -t

rm -f outfile

Or something similar