Sending Attachment using MIME in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending Attachment using MIME in UNIX
# 1  
Old 05-02-2010
Sending Attachment using MIME in UNIX

Hi,

I am using the below code for sending attachment in UNIX but only blank attachment is coming in email even the content is not coming.

Please help!!!

Code:
export CONTENT="${DIR}/${RUN_DATE}_mailbody.txt"
export SUBJECT="Search Result for Pattern - ${1}"
export ATTACH=${2}
(
echo "Content-Transfer-Encoding: 7bit"
echo "Content-Type: multipart/mixed; boundary=_----------=_10167391557129230"
echo "MIME-Version: 1.0"
echo "To: ${EMAIL_ADR}"
echo "Subject: ${SUBJECT}"
echo "--_----------=_10167391557129230"
echo "Content-Type: text/html"
echo "Content-Transfer-Encoding: binary"
echo "Content-Disposition: inline"
cat ${CONTENT}
echo "--_----------=_10167391557129230"
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Type: application/text; name=$ATTACH"
echo "Content-Transfer-Encoding: base64"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo "Content-Disposition: attachment; filename=$ATTACH"
echo "--_----------=_10167391557129230--"
echo "."

Thanks,
Rajesh

Last edited by Scott; 05-02-2010 at 06:24 PM.. Reason: Code tags, please...
# 2  
Old 05-02-2010
is there some reason not to use uuencode?

Code:
uuencode ${2} ${2} | /usr/bin/mailx -s "$SUBJECT" < $CONTENT

# 3  
Old 05-02-2010
Hi,

I need the email in HTML format that's why I am using MIME.

Thanks,
Rajesh
# 4  
Old 05-02-2010
Hard to follow from the script posted whether you want the html to appear in the message body or in as an attachment.
Also it would help to see examples of the data and the command used to invoke the script.


If you need an attachment, maybe try jim mcnamara's post with an attachment filename ending in ".htm" and leave the hard work to the mail client.
# 5  
Old 05-02-2010
I want the message body in HTML format and the attachment as it is.
# 6  
Old 05-02-2010
Thank you for the examples.
# 7  
Old 05-02-2010
Does this shell script even work? There are no spaces between echo and the string to be echoed, e.g.
Code:
echo"MIME-Version:1.0"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

MIME type for sending gzip file as attachment in email

Hello, I am trying to send a gzip file on email using below command but the zipped file received on email is corrupt. mailsend -smtp $smtpip -content-type 'application/x-gzip' -mime-type "application/x-gzip" -t $receiver -f $sender -sub "$subject" -M "$MSG" -attach $file file name is ... (1 Reply)
Discussion started by: tushar.modgil
1 Replies

2. UNIX for Beginners Questions & Answers

Need help sending attachment via mailx

Hello, I am new to the Unix thing, and I am having trouble sending attachments via shell client putty through mailx. The command I use is $ mailx -s "Subject" user@blah.com < attachment.txt but everytime I do that it would say Cannot open attachment.txt I have the file save to my computer... (5 Replies)
Discussion started by: mrobin20
5 Replies

3. Shell Programming and Scripting

Sending an Email using MIME protocol

Hi All, I just need to send an email using MIME protocol from perl script. The data of an email should be a HTML table(contains some datas). I just tried to send a normal text which is working fine whereas if i insert HTML tags i am getting errors. I just tried like below $mail_host =... (3 Replies)
Discussion started by: prasanna2166
3 Replies

4. UNIX for Dummies Questions & Answers

Sending mail in UNIX with body and attachment(.txt) using sendmail command

Hi All, In my .ksh script, I am sending an email with body and attachment (.txt) using sendmail command. I am able to receive the attachement along with the body of the mail. But I am getting special characters along with the content in the .txt. Also the alignment is incorrect. Can you please... (7 Replies)
Discussion started by: KRR
7 Replies

5. Shell Programming and Scripting

uuencode to MIME email attachment converter?

Hello all, we have an IMAP email system here that basically uses email as the transport for a transaction processing system. Users submit their transaction via an email, and our in-house application pulls the emails from the IMAP server and processes the transaction. Our problem is that we have... (0 Replies)
Discussion started by: lupin..the..3rd
0 Replies

6. Shell Programming and Scripting

MIME - HTML mail with Excel attachment - Please help!

#!/bin/ksh ( echo "MIME-Version: 1.0" echo "Content-Type: multipart/mixed; boundary=frontier" echo "--frontier" echo "Content-Type: text/html" echo "Content-Disposition: inline" echo "\n" echo "<html><body><h1>this is html formatted text</h1></body></html>" echo "--frontier" echo... (1 Reply)
Discussion started by: thulasidharan2k
1 Replies

7. Shell Programming and Scripting

Sending Attachment using MIME::Lite and Net::SMTP

Hello, I'm a newbie perl scriptor and i'm trying to figure out why i can't send an email using MIME::Lite with Net::SMTP. I keep receiving the following error: SMTP MAIL command failed: 5.7.1 Helo invalid . at attach1.pl line 31 The error keeps coming from the very last line... (2 Replies)
Discussion started by: xmaverick
2 Replies

8. UNIX for Dummies Questions & Answers

Sending attachment to webmail using UNIX

Hi, I am using Unix commands to send email with attachment from SAP. Within the organization(company email) the attachment is perfect, when I am trying to send as an web mail (yahoo) the attachment is not appearing and junk chars are coming as body. Someone suggested that I can use MIME,... (4 Replies)
Discussion started by: supriya5980
4 Replies

9. Shell Programming and Scripting

Problem sending excel attachments with MIME::Lite in perl

I am running a perl script that generates an excel doc and then emails it as an attachment. I can generate the excel file fine. I can scp it from the box and open it with no problems. When I send it over email, the file does open properly. The file in email is only 288 B, but on the server it is... (1 Reply)
Discussion started by: Mike_the_Man
1 Replies

10. UNIX for Dummies Questions & Answers

Issue on sending a mail with attachment using unix script ?

Issue on sending a mail with attachment using unix script ? Below is my code and is working fine and there is a issue in the attachment, the attachment file printing as a text-encripted message in the mail draft box instead of putting as a attachment (cat $msg; uuencode $attach1 in1.txt ;... (2 Replies)
Discussion started by: gksenthilkumar
2 Replies
Login or Register to Ask a Question