Visit Our UNIX and Linux User Community

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


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 encode the file but it is coming as a junk character in the mail body (actual mail received)

uuencode /tmp/tmp-mail.txt attach.txt | /usr/lib/sendmail -t -n -f root

uuencode /tmp/tmp-mail.txt attach.txt | mailx -s "Test attachment"

in a script taken from this forum i used this way.

export MAILTO=""
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 '---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

export FROMDIR=/aemu


( cat <<-TEXT

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

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

for FNAME in *.sql
   uuencode ${FNAME} ${FNAME}
) | 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....

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

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

Mail sending is ok but not the attachement.

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

begin 644 /aemu/CMW_A02_2.sql
M1%)/4"!404),12!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F<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
M15].3SUB+D))3$Q?4D5&7TY/*"LI(&%N9 T*82Y)3E9/24-%7TY//6,N0DE,
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/

# 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

that also i tried initially. with -m 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....

Previous Thread | Next Thread
Test Your Knowledge in Computers #721
Difficulty: Easy
In 2011, Alan Minsky was inducted into IEEE Intelligent Systems AI Hall of Fame for the "significant contributions to the field of AI and intelligent systems&".
True or False?

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" < 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=`grep "Tot Agents " snapshot.dbm` if (( $? == 0 )); then mailx $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. 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

Featured Tech Videos