YZlat
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 "mail -s "T...""
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 "mail -s "T...""
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.
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.
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/bi n:/usr/bin :/etc:/usr /sbin:/usr /ucb:/home /oracle/bi n:/usr/bin /X11:/sbin :.:/u01/ap p/oracle/p roduct/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
I ceched the PATH variable and it is as follows
/home/oracle:/usr/local/bi
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
/usr/bin/uuencode filename.html | /usr/bin/mail -s 'Subject' user@example.com
ASKER
that gave me
<p>
SP2-0734: unknown command beginning "/usr/bin/m..." - rest of line ignored.
<br>
SP2-0734: unknown command beginning "/usr/bin/u..." - rest of line ignored.
<p>
SP2-0734: unknown command beginning "/usr/bin/m..." - rest of line ignored.
<br>
SP2-0734: unknown command beginning "/usr/bin/u..." - rest of line ignored.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
that's exactly what I do, I store the command in a ksh file and run it from the UNIX prompt
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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?
What else does your ksh script do? Does it do any Oracle stuff?
ASKER
yes, it retrieves data from oracle database, writes it to a fiel and then, supposedly sends this file over the e-mail
ASKER
Oh, I see! I probably need to exit from sqlplus in my ksh file first, before sending an e-mail
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How can I exit Oracle CLI in my script?
ASKER
mail -a "Content-type: text/html" -s "Subject" user@example.com < filename.html
gave me an error: "mail: Not a recognized flag: a"
gave me an error: "mail: Not a recognized flag: a"
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
ASKER
tried both, same result
I tried
exit;
exit
/
quit;
and
quit
/
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?
ASKER
here is my code:
if I remove eexit, I get an error, but if I leave the exit; there, it exits right after writing to the file
#!/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
if I remove eexit, I get an error, but if I leave the exit; there, it exits right after writing to the file
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
-a was *once* mailx only, but most standard OSes today have it on the standard 'mail' program.
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?
ASKER
I tried using mailx command but got same error:
mailx: Not a recognized flag: a
mailx: Not a recognized flag: a
Add the headers into your mail that I had posted above.
ASKER
where do I add those headers?
ASKER
I already have this in my html file
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<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
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
ASKER
I can't really edit html file, it gets generated by sql plus
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
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
( find the path with `which mail` and `which uuencode` )