Unix shell script

How to send email with attachement through unix shell script ?
digs developerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Same mailx command from your previous question but with one new twist:

uuencode theattachment | mailx -s "sending an attachment" someemail@mailserver.com

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
digs developerAuthor Commented:
Could you please tell me where is the attached file syntax and how can I attcahed the test.txt file.
slightwv (䄆 Netminder) Commented:
>>Could you please tell me where is the attached file syntax and how can I attcahed the test.txt file.

uuencode takes the file you want to attach and 'encodes' it so mailx can handle it.

uuencode test.txt   | mailx -s "sending an attachment" someemail@mailserver.com
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mail or mailx do not take attachments directly. What can be done, is to create archive file then you may compress it, then uuencode the compressed file:

tar cf - file1 file2 file3 dir1 | compress | uuencode myfiles.tar.Z | mailx -s "email with attachments" user@domain.com
johnsoneSenior Oracle DBACommented:
While mail or mailx is not capable of sending a multi-part message, sendmail, which is the underlying program to everything, is capable of doing it.  With the methods already posted, all of which will work, you can only send one attachment, and no body to the message.  The way around this is to create your own MIME encoded file and send that to sendmail.

While it sounds difficult, if you are sending only text files.  No special characters, no images, nothing like that, there is actually no need to encode anything.  What you need to do is to create a single text file that has your message and attachment included and then pass it to sendmail.

This page has an excellent example file -> http://msdn.microsoft.com/en-us/library/ms526560(v=exchg.10).aspx

If you want to put in multiple attachements, not a problem.  Just create more boundaries and put all the relevant information to identify the additional attachments.

It has been quite a while since I have written a script to do this and I don't think I have a server set up right now that I can test it on, but those are the basics.  It really is pretty easy to do.  You just have to do the legwork that mail or mailx does.
digs developerAuthor Commented:
Thank you !
slightwv (䄆 Netminder) Commented:
>>Thank you !

This implies you found a solution.

If so don't forget to properly close out the question by accepting one or more posts that helped you resolve the question.
digs developerAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for digs developer's comment #a40277120

for the following reason:

I got the solution.

Thank you for your help !!
slightwv (䄆 Netminder) Commented:
I have to again object to choosing your own post as the solution.  Especially when it isn't a solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.