Sending attachement using mailx


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Sending attachement using mailx
# 1  
Old 09-28-2009
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 character in the mail body (actual mail received)

Code:
uuencode /tmp/tmp-mail.txt attach.txt | /usr/lib/sendmail -t -n -f root aemunathan.r@gmail.com


uuencode /tmp/tmp-mail.txt attach.txt | mailx -s "Test attachment" aemunathan.r@gmail.com

in a script taken from this forum i used this way.
Code:
#!/usr/bin/ksh

export MAILTO="aemunathan.r@gmail.com"
export SUBJECT="Mail Subject"
export BODY="/tmp/tmp-mail.txt"
export ATTACH="/aemu/CMW_A02_2.sql"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $BODY
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: base64"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 uuencode --base64 $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5--'
) | /usr/lib/sendmail $MAILTO

this resulted in uuencode illegal option base 64

another script i tried is
Code:
#!/bin/ksh

export TOADDR=aemunathan.r@gmail.com    
export FROMDIR=/aemu

cd ${FROMDIR}

( cat <<-TEXT
Hi,

Please find enclosed all of the text files found
in the directory ${FROMDIR} as of $(date).

Sincerly, $(grep root  /etc/passwd| cut -d: -f5)
TEXT

for FNAME in *.sql
do
   uuencode ${FNAME} ${FNAME}
done
) | mailx -s "${FROMDIR}/*.sql as of $(date)" ${TOADDR}

this resulted in junk charaters in the body of the mail

Any one help me out what mistake am doing here....

Thanks
Aemu
# 2  
Old 09-28-2009
uuencode $ATTACH $ATTACH |mailx -s "SUBJECT" $MAILTO

Please try this one.....
# 3  
Old 09-28-2009
Hi

Mail sending is ok but not the attachement.

am getting junk like this in the body of the mail...

Quote:
begin 644 /aemu/CMW_A02_2.sql
M1%)/4"!404),12!C;7=?03 R7W1A>#L-"F-R96%T92!T86)L92!C;7=?03 R
M7W1A>"!A<PT*4T5,14-4(&)I;&Q?<F5F7VYO+%-532A!34]53E0I+S$P,"!S
M97)V:6-E7W1A>" @1E)/32 -"F%R8F]R+D))3$Q?24Y63TE#15]$151!24Q
M=&-S,VQI;FL-"E=(15)%($))3$Q?4D5&7VYO(&EN("AS96QE8W0@:6YV;VEC
M95]N;R!F<F]M(&-M=U]!,#(I#0I!3D0@4U5"5%E015]#3T1%(#T@+34-"BTM
M04Y$(%-50E-#4E].3SP^, T*1U)/55 @0ED@8FEL;%]R969?;F\[#0H-"@T*
M9')O<"!T86)L92!C;7=?03 R7V1I<SL-"F-R96%T92!T86)L92!C;7=?03 R
M7V1I<R!A<PT*4T5,14-4(&)I;&Q?<F5F7VYO+%-532A!34]53E0I+S$P,"!D
M:7,@($923TT@#0IA<F)O<BY"24Q,7TE.5D])0T5?1$5404E,0'1C<S-L:6YK
M#0I72$5212!"24Q,7U)%1E]N;R!I;B H<V5L96-T(&EN=F]I8V5?;F\@9G)O
M;2!C;7=?03 R*0T*04Y$(%-50E194$5?0T]$12 ]("TQ,0T*04Y$(%-50E-#
M4E].3SP^, T*1U)/55 @0ED@8FEL;%]R969?;F\[#0H-"@T*#0ID<F]P('1A
M8FQE(&-M=U]!,#)?<F5N=#L-"@T*8W)E871E('1A8FQE(&-M=U]!,#)?<F5N
M="!A<PT*4T5,14-4(&)I;&Q?<F5F7VYO+%-532A!34]53E0I+S$P,"!R96YT
M("!&4D]-( T*87)B;W(N0DE,3%])3E9/24-%7T1%5$%)3$!T8W,S;&EN:PT*
M5TA%4D4@0DE,3%]2149?;F\@:6X@*'-E;&5C="!I;G9O:6-E7VYO(&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(&%C8V]U;G1?;F\[#0H-"@T*
M#0IS96QE8W0@82Y)3E9/24-%7TY/+&$N04-#3U5.5%].3RQA+D585$523D%,
M7TE$($U/0DE,15].3RQB+E5304=%+&,N4D5.5"QD+D1)4RQE+D%$2BQF+E-%
M4E9)0T5?5$%8+&<N1%5%#0IF<F]M(&-M=U]!,#(@82QC;7=?03 R7W5S86=E
M(&(L8VUW7T$P,E]R96YT(&,L8VUW7T$P,E]D:7,@9"QC;7=?03 R7V%D:B!E
M+&-M=U]!,#)?=&%X(&8L8VUW7T$P,E]B:6QL(&<-"G=H97)E(&$N24Y63TE#
M15].3SUB+D))3$Q?4D5&7TY/*"LI(&%N9 T*82Y)3E9/24-%7TY//6,N0DE,
M3%]2149?3D\H*RD@86YD#0IA+DE.5D])0T5?3D\]9"Y"24Q,7U)%1E].3R@K
M*2!A;F0-"F$N24Y63TE#15].3SUE+D))3$Q?4D5&7TY/*"LI(&%N9 T*82Y)
M3E9/24-%7TY//68N0DE,3%]2149?3D\H*RD@86YD( T*82Y!0T-/54Y47TY/
F/6<N04-#3U5.5%].3PT*;W)D97(@8GD@82Y!0T-/54Y47TY/#0I/

end
# 4  
Old 09-28-2009
Not all versions of mailx support MIME attachments.

Check to see if your version of mailx has a -m command line option. It it has, use that option to create a MIME attachment.

If not, you could use utilities such as mpack/munpack or mmencode to create a MIME attachment.
# 5  
Old 09-28-2009
Hi

that also i tried initially. with -m option...my server does not support it...

do i need to install mpack...

i tried searching *encode* in my server from root directory....found only uuencode...nothing else....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. Solaris

Mailx sending but not receiving

Hi, I need help with mailx. When I run the below mailx command, it works fine because the exit code is fine, and the message is sent to /usr/mail/<id> echo "This is a test message" | mailx -s "Test" <my email address> My question is, how do I get it to reach my email address (on outlook... (2 Replies)
Discussion started by: ChicagoBlues
2 Replies

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

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

5. Shell Programming and Scripting

sending variable value via mailx

Hi all, I need to send a variable value in the script through mailx. Please find the script below but its not working. agents.sh: agents=`grep "Tot Agents " snapshot.dbm` if (( $? == 0 )); then mailx abc@gmail.com $agents fi (3 Replies)
Discussion started by: db2cap
3 Replies

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

7. AIX

Mailx Not sending

How can I check to see how/why my mailx program is not sending? /var has enough room. -Thanks ---------- Post updated at 08:48 AM ---------- Previous update was at 08:35 AM ---------- I tested the mailx to send with this command: echo "This is going to be body of the mail" |mailx... (1 Reply)
Discussion started by: tfort73
1 Replies

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

9. Shell Programming and Scripting

sending mail through mailx

while trying to send a mail, though the output file doesn't contain any exclamatory mark(!), i am getting that in the mail with an extra line. please help me out from this ASAP. (3 Replies)
Discussion started by: pvamsikr
3 Replies

10. UNIX for Dummies Questions & Answers

sending email from mailx

hi can i know how to use mailx to send email to my lotus email account? i wan to send a file in a directory as an attachment and then email to lotus. can show me the command line to do it? thanks a lot (1 Reply)
Discussion started by: legato
1 Replies
Login or Register to Ask a Question