sendmail with attachment not working


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sendmail with attachment not working
# 1  
Old 06-26-2012
sendmail with attachment not working

dear all

I have below function which send an email, but if I need to add an attachement it won't work instead it write some jibberish to body of the email

Code:
begin 644 SIGN_OFF_AP_20120626.csv
M4TE'3E]/1D9?4TA%150L351-7T1!5$4L0D]/2RQ35$%455,L5D%25%E012Q#
%3U5.5`H`
`
end

Code:
function send_mail_html
{
SUBJECT="$1"
FROM="test@linux.site"
FILENAME=$4

(
        echo "Subject: $SUBJECT"
        echo "From: $FROM"
        echo "MIME-Version: 1.1"
        echo "Content-Type: text/html"
        echo "Content-Transfer-Encoding: 8bit"
        echo "Content-Disposition: inline"
        echo "<html>"
        echo "<body>"
        echo "<FONT FACE="Courier New">"
        echo "<PRE>"
        uuencode ${FILENAME} $(basename ${FILENAME})
        cat $3
        echo "</PRE>"
        echo "</FONT>"
        echo "</body>"
        echo "</html>"
) | /usr/sbin/sendmail $2
}

and calling above function as below with proper placeholder

Code:
send_mail_html "${mailsubject}" "${mailto}" "/scripts/signoff/sos_template_ntd.mail" "${spool_to}"

can anyone suggestion, where and what exactly ggone wrong with the function?

Last edited by manas_ranjan; 06-26-2012 at 08:45 AM..
# 2  
Old 06-26-2012
The "gibberish" is the output from uuencode.
Just for interest, it decodes to:
Code:
SIGN_OFF_SHEET,MTM_DATE,BOOK,STATUS,VARTYPE,COUNT

The section headers you are giving to sendmail look a bit unlikely.

What Operating System and version is this?

If you search the forums for "sendmail mime attachment" there are several hits.
This thread contains an example relevant to you (even if it didn't match the original requirement).
https://www.unix.com/shell-programmin...-together.html
# 3  
Old 06-26-2012
wow!! decode message are totally correct
I'm using SUSE Linux and ksh

when you said "The section headers you are giving to sendmail look a bit unlikely" does it eman for the attachment ?

anyway I'm looking those links..thanks for that.
But would you mind, letting me know, how to check which uuencode I'm using??

---------- Post updated at 07:50 AM ---------- Previous update was at 07:21 AM ----------

hi Methyle,

I have gone thru your suggested link, and I changed my function a bit
good thing is I'm getting CSV as an attachment but without any content in that attachment..could you assist.....

Code:
(
        echo "Subject: Test"
        echo "From: test@linux.site"
        echo "MIME-Version: 1.1"
	echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
	echo
 	echo '---q1w2e3r4t5'
        echo "Content-Type: text/html"
        echo "Content-Transfer-Encoding: 8bit"
        echo "Content-Disposition: inline"
        echo "<html>"
        echo "<body>"
        echo "<FONT FACE="Courier New">"
        echo "<PRE>"
	cat /var/tmp/test
	echo '---q1w2e3r4t5'
	echo "Content-type: Application/Octet-stream; name=/var/tmp/SIGN_OFF_AP-Summary20120626.csv; type=Binary" 
	echo "Content-Transfer-Encoding: X-UUencode"
	echo 'Content-Disposition: attachment; filename="'/var/tmp/SIGN_OFF_AP-Summary20120626.csv'"'
        uuencode "/var/tmp/SIGN_OFF_AP-Summary20120626.csv" "SIGN_OFF_AP-Summary20120626.csv"
	echo '---q1w2e3r4t5--'
        echo "</PRE>"
        echo "</FONT>"
        echo "</body>"
        echo "</html>"
) | /usr/sbin/sendmail manas@axe.com


Last edited by Franklin52; 06-26-2012 at 09:53 AM.. Reason: Please use code tags for data and code samples
# 4  
Old 06-26-2012
Maybe look again at the example, particularly the boundary lines and significant blank lines at the end of the mail body. The HTML bit is alien to me and it may be easier to test without it to start with.
# 5  
Old 06-26-2012
Why everyone allways try to reinvent the wheel Smilie

Why dont you use something like this:
Code:
http://caspian.dotconf.net/menu/Software/SendEmail/

Hope it helps you Smilie
# 6  
Old 06-26-2012
hi Methyl,

I removed the HTML tag from the function as well as I changed the boundary, but still no content in the attachment.

Code:
(
        echo "Subject: Test"
        echo "From: test@linux.site"
        echo "MIME-Version: 1.0"
	echo "Content-Type: multipart/mixed; boundary=Message-Boundary-"$$
 	echo "--Message-Boundary-"$$
        echo "Content-Type: text/html; charset=US-ASCII"
        echo "Content-Disposition: inline"
        echo ""
        echo ""
	cat /var/tmp/test
	echo ""
	echo "--Message-Boundary-"$$
	echo "Content-type: Application/Octet-stream; name=SIGN_OFF_AP-Summary20120626.csv; type=Binary" 
	echo "Content-Transfer-Encoding: X-UUencode"
	echo "Content-Disposition: attachment; filename=SIGN_OFF_AP-Summary20120626.csv"
        uuencode "/var/tmp/SIGN_OFF_AP-Summary20120626.csv" "SIGN_OFF_AP-Summary20120626.csv"
) | /usr/sbin/sendmail manas@axe.com

has it to do with FILENAME ??

---------- Post updated at 08:57 AM ---------- Previous update was at 08:37 AM ----------

Quote:
Originally Posted by cabrao
Why everyone allways try to reinvent the wheel Smilie

Why dont you use something like this:
Code:
http://caspian.dotconf.net/menu/Software/SendEmail/

Hope it helps you Smilie
Thanks for your suggestion, but couldn't add new package in my already built system and a loads of procedure involved which might take longer than the solution from the existing one. you know , the process of corporate world....Smilie

Last edited by manas_ranjan; 06-26-2012 at 10:55 AM..
# 7  
Old 06-26-2012
Possibly because the lines preceding your uuencode are in a different order from the sample and contain subtle differences.
Also worth trying .txt as the file extension in case your browser has something unusual associated with .csv .
If the original file is in unix text format you may need to convert it to MSDOS format (using ux2dos or unix2dos program) before the uuencode.


I wish I could try your script but my sendmail generates the MIME headers automatically.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with attachment in sendmail

Hi Folks I have below code, which is able to successfully send the content of the output file as html which is body, but i did tried uuencode & mailx -a for sending attachments but to no avail. cat - ${Output_File} <<EOF| /usr/sbin/sendmail -oi -t #From: ${MAILFROM} To: ${MAILTO} Subject:... (5 Replies)
Discussion started by: nikhil jain
5 Replies

2. Shell Programming and Scripting

Sendmail cmd for html body and attachment not working

Hi, I am having trouble in sending a mail with html body and attachment (csv file). We don't have uuencode or mutt (not allowed to install as well) The below code is perfectly working for sending the html body alone: export MAILTO=abc@xyz.com export CONTENT="/home/abc/list.html"... (2 Replies)
Discussion started by: close2jay
2 Replies

3. Shell Programming and Scripting

Sendmail with attachment

Hello people, I only have sendmail and uuencode on a Oracle (RH) linux server. While: /usr/bin/uuencode awr.html awr.html | /usr/sbin/sendmail myemail@company.com Is working fine, the ideal for me is to do something like: echo "To: me@company.com" > /home/vasilis/msg.txt echo "Subject: DB... (3 Replies)
Discussion started by: drbiloukos
3 Replies

4. Shell Programming and Scripting

Send attachment through sendmail

Hi, I am trying to send log file of a job run in unix machince through sendmail.Though I am able to send the text but it is not sending as attachment. Could you please look into the code and let me know where I have gone wrong fdate=`date %Y%j`... (2 Replies)
Discussion started by: Rossdba
2 Replies

5. Shell Programming and Scripting

Sendmail with HTML body and attachment

I have an HTML file I am currently sending in the body of an email. I now have a need to send a csv attachment along with it. I can ONLY use sendmail as mutt and xmail etc are not on the server. Here is what I am currently using: It is possible to add code to add an attachment ??!? { ... (8 Replies)
Discussion started by: atelford
8 Replies

6. Shell Programming and Scripting

sendmail attachment issue

Hi All,, After long time, might be this is nth time post on this forum for the same query...but i tried browsing for sometime and i did not get what i wanted :) i have following syntax in my shell scripting.. (cat filename.txt uuencode attachment attachment)|/usr/lib/sendmail -t... (4 Replies)
Discussion started by: Shahul
4 Replies

7. UNIX for Dummies Questions & Answers

sendmail attachment problem

Hello, i am sending email with following command. The problem is the attachment is displayed as inline text instead of a file attached to email. What should i do? I don't have chance to install new binaries to the server (SunOS) ( \ echo From: Sender ; \ echo Subject: Testing ; \... (1 Reply)
Discussion started by: yakari
1 Replies

8. UNIX for Dummies Questions & Answers

Using Sendmail (& attachment)

Hi, This is my first thread. Iam trying the following: OS: Sun Database: DB2, Informix, Oracle * Get the status of the database (using database command line options) * pipe to a text file * send mail of the text file to receiptents. TODO1: First step i tried to send a test message.... (3 Replies)
Discussion started by: kenkanya
3 Replies

9. Solaris

attachment using sendmail

Hi, I use the sendmail command to send automatic e-mail in my control programs, but I'd like to know if there's a non interactive way to send an attachment, like a small text file through sendmail command. I didn't find a way in the man, so anyone has already done it?.. give an example for the... (4 Replies)
Discussion started by: vastare
4 Replies
Login or Register to Ask a Question