sending attachement in mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sending attachement in mail
# 1  
Old 02-10-2010
sending attachement in mail

Hi ,
I am using the below code to send mail through a script which run as a cron job.

Code:
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
!)

echo "$daemail" > msg.tmp
echo  >> msg.tmp
email=`cat msg.tmp`
echo "$email" | /usr/sbin/sendmail -t

If i want to send hi.csv as a attachment..how should the code be modified.
can someone help me which the code.

Thanks,
Ahamed.

Last edited by pludi; 02-10-2010 at 04:27 PM.. Reason: code tags, please...
# 2  
Old 02-10-2010
Quote:
Originally Posted by ahamed
Hi ,
I am using the below code to send mail through a script which run as a cron job.

Code:
msgdate=`date +"%a, %e %Y %T %z"`


Your date format is missing the month; I think you want:
Code:
msgdate=`date +"%a, %e %b %Y %T %z"`

Quote:
Code:
daemail=$(cat <<!
From: $from
To: $emailtarget
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed;
Content-Disposition: inline
$priority

$CONTENT
!)


Why are you using cat? Assign the string directly:
Code:
daemail="From: $from
To: $emailtarget
Subject: $subject
Mime-Version: 1.0
Content-Type: multipart/mixed;
Content-Disposition: inline
$priority

$CONTENT"

Quote:
Code:
echo "$daemail" > msg.tmp
echo  >> msg.tmp
email=`cat msg.tmp`
echo "$email" | /usr/sbin/sendmail -t

If i want to send hi.csv as a attachment..how should the code be modified.
can someone help me which the code.

If you want to use sendmail, you'll have to uuencode the attachment.

I find the easiest way to send attachments in a script is to use alpine or mutt.
# 3  
Old 02-10-2010
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sending csv file as an attachement from Linux

Hi i am trying to send a csv file as an attachment via mail from linux. i am using the below script. echo "X-Mailer: htmlmail" $VERSION echo "Mime-Version: 1.0" echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"' echo '---q1w2e3r4t5' echo "Content-Type: text/html; charset=US-ASCII"... (1 Reply)
Discussion started by: mohanalakshmi
1 Replies

2. 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

3. Shell Programming and Scripting

Mail sending with multiple attachement(pdf and csv) with html content from Linux

Hi, We have a requirement to send multiple attachment(pdf and csv) along with html content in a single mail. For that we are using uuencode. It is working for single pdf attachment and html content. But we are unable to send both pdf and csv attachment with html content. Below is the script.... (5 Replies)
Discussion started by: dholea
5 Replies

4. 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

5. Shell Programming and Scripting

Sending attachement using mailx

Hi I tried reading docs from this forum and googled it...but i couldnt get the answer for attaching a document in mail. I need it to be the actual attachement not adding the content of the file to the body of the mail.. i used uuencode ...to encode the file but it is coming as a junk... (4 Replies)
Discussion started by: aemunathan
4 Replies

6. 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

7. Shell Programming and Scripting

Email sending attachement with two file comparision

Hi guys, I have two files . One file contains log record and another file contains emailids which is supposed to send it users File1 : Name : abc_xyz_data.txt Which contains log record File 2 : Name : abc_xyz_mailids.txt Which contains emailids. abc@test.com bcd@test.com I... (4 Replies)
Discussion started by: orabalu
4 Replies

8. 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

9. Shell Programming and Scripting

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... (6 Replies)
Discussion started by: chgopi
6 Replies
Login or Register to Ask a Question