Avatar of digs developer
digs developer
 asked on

Unix shell script

How to send email with attachement through unix shell script ?
Unix OSLinux

Avatar of undefined
Last Comment
slightwv (䄆 Netminder)

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
slightwv (䄆 Netminder)

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
digs developer

ASKER
Could you please tell me where is the attached file syntax and how can I attcahed the test.txt file.
slightwv (䄆 Netminder)

>>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
omarfarid

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
Your help has saved me hundreds of hours of internet surfing.
fblack61
johnsone

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 developer

ASKER
Thank you !
slightwv (䄆 Netminder)

>>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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
digs developer

ASKER
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)

I have to again object to choosing your own post as the solution.  Especially when it isn't a solution.