mailx help required


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting mailx help required
# 1  
Old 11-18-2005
mailx help required

Is there anyway to send a file as an attachment to recepients?

I am using this command but it write everything in BODY part of a mail. I need it as an attachment in mail.

mailx -s "Alert: Ora-errors for instance $inst" m@yahoo.com < $logfile

Please advice.

Regards,
Malay Maru
# 2  
Old 11-18-2005
try this uuencode $logfile logfile.txt | mailx -s "Alert" m@yahoo.com
# 3  
Old 11-20-2005
I use perl to do this sort of thing. It will create the message using MIME, so you can read it easily in Outlook or another (more secure) modern mail client. PM me or send me email if you could use such code.
-Mike
# 4  
Old 11-20-2005
Sending MIME messages, using Perl, with a ksh Script

By popular demand, here's how to send email using Perl with MIME attachments. I used to include a PDF attachment but my users are happier with plain text, so I haven't tested the $top->attach statement, but it's close. Caveat programmer.

Code:
#!/bin/ksh
# Usage:  $0 message attachment
# where message is a file containing an arbitrary text message and attachment
# is a gif file you want to attach.  If you don't want to use the latter feature, delete
# the line below that begins with \$top-attach
# Other filetypes are left to the reader to discern; do a google search for 
# perl mime::entity for more info

$eMAIL="recipient@example.com"
/opt/perl/5.8.0/bin/perl -e "use MIME::Entity; \$message=qx($1);
        \$top = MIME::Entity->build( \
        From => \"SomebodysName\\@donotreply.com\", \
        To => \"$eMAIL\", Subject => \"A nice picture\", \
        Data => \$message ); \
       \$top->attach(Path => \"$2\", Type => "image/gif", Encoding => "base64");\
        open MAIL, \"| /usr/lib/sendmail -t -oi -oem -v\" or die \"open: \$!\"; 
\$top->print(\\*MAIL); \
        close MAIL; \
        print \"\$message\\n------------------\\n\"; \
         \$top->print(); \
" > /tmp/out$$ &

# Here's some bonus code at no extra charge.  Sometimes sendmail must wait
# for a downstream server to reply.  This gives you some feedback.  notice that
# the perl command must match the perl command you called, above.
# So if you change your perl path, change it here too.  Hmm... I should probably
# put that in a shell variable, but you get what you pay for :-)
lines=1
cycles=30
while [ "$lines" -gt 0 -a $cycles -gt 0 ] ; do
        lines=`ps -j -o args | grep "/opt/perl/5.8.0/bin/perl -e use MIME::Entity" | grep -v grep | wc -l`
        if [ $lines -gt 0 ] ; then
                printf "."
                sleep 1
        else
                printf "\nMail sent. Wait a couple of minutes for it to arrive.\n"
                break
        fi
        if [ $cycles -eq 15 ] ; then
                printf "\nErgh. Mail seems slowish, still trying!\n";
                sleep 1
                printf "."
        fi
        cycles=`expr $cycles - 1`
done
if [ "$lines" -gt 0 ] ; then
        printf "\nMail is slow today. Still trying...  I'll check every minute.\n"
        printf "From now on, each hash symbol ( # ) represents 1 minute of time.\n"
fi
while [ "$lines" -gt 0 ] ; do
        lines=`ps -j -o args | grep "/opt/perl/5.8.0/bin/perl -e use MIME::Entity" | grep -v grep | wc -l`
        if [ $lines -gt 0 ] ; then
                sleep 60
                printf "#"
        else
                printf "\nMail sent. Wait a couple of minutes for it to arrive.\n"
        fi
done


Last edited by mschwage; 11-20-2005 at 09:58 PM.. Reason: coding error...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Linux

Mailx

We have configured mailx Linux server. When send mail from Linux server it is not going How to trouble shoot the root cause step by step (3 Replies)
Discussion started by: pmsuper
3 Replies

2. Shell Programming and Scripting

Mailx: How to send a attachment using mailx command

Hi All, Can anyone please provide the command for sending an mail with attachment using mailx command. Thanks in Advance :) Regards, Siram. (3 Replies)
Discussion started by: Sriram.Vedula53
3 Replies

3. Shell Programming and Scripting

Getting required fields from a test file in required fromat in unix

My data is something like shown below. date1 date2 aaa bbbb ccccc date3 date4 dddd eeeeeee ffffffffff ggggg hh I want the output like this date1date2 aaa eeeeee I serached in the forum but didn't find the exact matching solution. Please help. (7 Replies)
Discussion started by: rdhanek
7 Replies

4. Ubuntu

mailx

hi, I am working on a ksh script and i want to be able to send a email using mailx. if ] || ] then echo "send email" mailx -s "Subject goes here" <email address>; fi thats what i have so far, in place of "<email address>" I have my actualy email address and I want to add a body with... (6 Replies)
Discussion started by: mike509123
6 Replies

5. UNIX for Advanced & Expert Users

mailx

We are using mailx to send email alerts. On occasions, it is updating our Distribution list with the mesage content. The following is the relevant portion of the script :- MAILGROUP=`more $MDS/feeds/alerts/distribution.lst` export MAILGROUP echo " " | mailx -s "MDS Alert - Refresh Complete"... (6 Replies)
Discussion started by: Paul Byrne
6 Replies

6. Shell Programming and Scripting

mailX

I would like to get a solution .. how can i attach more than one file to a mail using mailx yep........ sure if test.dat is the file cat test.dat|uuencode test.dat|mailx -s "subject" mailid can be used for attaching test.dat how can we attach test1.dat and test2.dat (4 Replies)
Discussion started by: anumkoshy
4 Replies

7. Shell Programming and Scripting

mailx

Hi, Thanks in Advance !! I have a korn script which is used to mail the reports to the users. I'm using the mailx utility. The uid used for running the script is "cronman", so the mails recieved by users are id FROM:"cronman". Now i want to change the FROM address to another user name... (2 Replies)
Discussion started by: pradeep_desh
2 Replies

8. UNIX for Dummies Questions & Answers

mailx error message : mailx: NUL changed to @

If I use the "Mail" link instead of the "mail" link to ../mailx I get this error. Mail so-n-so @whatever.com mailx: NUL changed to @ Unknown command: "postmaster" The email still goes through but i get the error. If I use "mail" it goes thru without the error. Any ideas?? (2 Replies)
Discussion started by: BG_JrAdmin
2 Replies

9. Shell Programming and Scripting

mailx to to Dl

Is there any way that I can mailx to a distribution list without having a $HOME/.mailrc file? We have a distribution list in Outlook for our group say group@something.com. I am trting to do echo "Something"|mailx -s "Subject" group@something.com it doesnt work Any ideas? Thanks (1 Reply)
Discussion started by: sm321
1 Replies

10. Shell Programming and Scripting

Mailx

I am trying to write a shell script using the mailx command. My problem is that I want to send an email address in the CC: field. What option can I use with mailx to accomplish this. Any help would be very appreciative. (1 Reply)
Discussion started by: skammer
1 Replies
Login or Register to Ask a Question