How to send Mail with Attachement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to send Mail with Attachement
# 1  
Old 02-02-2006
How to send Mail with Attachement

Hi

Can somebody help me in wirting shell script in the following way.Desperately i have poseted this..

1.How can I connect to Oracle(Sqlplus) from UNIX.
2.After connecting to it I have to execute an oracle proceudure..
3.Execution of the procedure will give some set of rows..
4.The set of rows have to be 'Spool' to a seperate file and that file has to be sent to particular user as attachement.

Regards
Gopinath
# 2  
Old 02-02-2006
echo "Hi\n\n This is mail body \n\n Thanks & regards \n Myself." > /tmp/$$.mailbody

sqlplus -s $CONNECT_STRING <<EOF > /tmp/$$.attachment

your pl/sql block here to call the stored procedure

exit;
EOF

uuencode $$.attachment results.txt >> /tmp/$$.mailbody

mailx -s "SUB: Stored procedure results" yourname@email.com < /tmp/$$.mailbody

rm /tmp/$$.mailbody
rm /tmp/$$.attachment

do some checks with the results file to check that the stored procedure completed successfully or failed... otherwise you will get a email with the sql error in case if it failed.

Last edited by mahendramahendr; 02-03-2006 at 05:56 AM..
# 3  
Old 02-02-2006
hi mahendra ,

thanks a lot for your reply...i am not able to get "$$.mailbody" and "$$.attachment". could u please explain me what does these means.

regards
gopi
# 4  
Old 02-02-2006
Here is what I do. I simplified the code and remove the variables so you can understand better.

Code:
echo "To: user@mail.com" > mail.tmp
echo "From: your@mail.com" >> mail.tmp
echo "Subject: your subject" >> mail.tmp
echo "Your text" >> mail.tmp

uuencode path/attached_file attached_file >> mail.tmp
cat mail.tmp | /usr/sbin/sendmail -t

# 5  
Old 02-02-2006
$$ is nothing but a process id

The funda behind using $$ infront of file name is, if two people executing the same script, it won't overwrite others and end...

I'm just starting the file name with the process id... assuming the file will be unique if I include the process id in the file name...
# 6  
Old 02-03-2006
Hi mahendra ,

The script you gave me worked clearly with no alterations...My v.v.special thanks to you.

Have a nice days..

Regards
gopinath
# 7  
Old 02-03-2006
Closing the thread
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Send file attachement in mail

Hello, I am able to attache the file in UNIX/LINUX script using following code. MAILFORMAT="Please do not replay this mail.This mail is auto generated." echo -e $MAILFORMAT | mailx -r autoreplay@gmail.com -a filename -s "status" xyz@gmail.com But same I am not able attache... (6 Replies)
Discussion started by: nes
6 Replies

2. Shell Programming and Scripting

sending attachement in mail

Hi , I am using the below code to send mail through a script which run as a cron job. msgdate=`date +"%a, %e %Y %T %z"` daemail=$(cat <<! From: $from To: $emailtarget Subject: $subject Mime-Version: 1.0 Content-Type: multipart/mixed; Content-Disposition: inline $priority $CONTENT !)... (2 Replies)
Discussion started by: ahamed
2 Replies

3. Shell Programming and Scripting

attachement through mail command

Can't attach text files to 'mail' command. I dont have mutt or mailx to use on my server. so i have to use mail command any help would be great. Regards, Kiran (1 Reply)
Discussion started by: dddkiran
1 Replies

4. UNIX for Advanced & Expert Users

How to read mail attachement

I want to read attachements sent to unix mail id and save the attachement in folder. I may receive the mails from different mail clients(outlook, lotus ..etc). Attachements are in CSV(comma saperate) format. Let me know the shell script code for this. Regards, Venkat (1 Reply)
Discussion started by: svenkatareddy
1 Replies

5. Shell Programming and Scripting

query about Attachement in mail

Hi All, I have general query that ...in my script i used uuencode option like below. cd /location (cat test.txt uuencode test.csv test.csv ) | mail -s "test mail" "mail_id" but whenever i run the above command its giving error like below ./testscript.sh: uuencode not found: ... (1 Reply)
Discussion started by: Shahul
1 Replies

6. Shell Programming and Scripting

How to send a mail with attachement as well as message Body..?

Hi all, i am working with CSH, i want to know that how to send a mail in UNIX shell script (CSH) with attachment as well as message body. i know that how to send a mail with attachment and message body. but i want know both things in a single mail Suggession would be appreciate. ... (1 Reply)
Discussion started by: psiva_arul
1 Replies

7. UNIX for Dummies Questions & Answers

Send email with attachement-Getting connection refused by domain

Hi all, I am a newbie to unix. I need to send an email with an attachment in unix to some id like abc@some_company.com Code i have used is ------------Code--------------------------- #!/bin/ksh set -x #set -n #cript: unix_mail_withattachments.ksh # Aurthor: Ravin Maharaj #... (1 Reply)
Discussion started by: samuelc
1 Replies

8. UNIX for Dummies Questions & Answers

Send a mail with an attachement of a file

I wanted to try sending a mail with an attachement at command prompt in unix. Some one please advise that how we can do it ? Thanks, :) (2 Replies)
Discussion started by: gaddeg
2 Replies

9. UNIX for Dummies Questions & Answers

Send a mail with a subject and an attachement

Dear All: I want to send a message to a list of people with a subject and an attachement, currently I am using the following command into a shell script: uuencode $FILENAME.gz $FILENAME.gz | mail john.kennedy@mycompany.com m.m@mycompany.com With this command I can send the message for a... (1 Reply)
Discussion started by: josecollantes
1 Replies
Login or Register to Ask a Question