We help IT Professionals succeed at work.

Unix  shell script

digs developer
on
522 Views
Last Modified: 2014-09-03
How to send email with attachement through unix shell script ?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Could you please tell me where is the attached file syntax and how can I attcahed the test.txt file.
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019

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
CERTIFIED EXPERT
Top Expert 2007

Commented:
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 DBA
CERTIFIED EXPERT

Commented:
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.

Author

Commented:
Thank you !
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019

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.

Author

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 !!
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019

Commented:
I have to again object to choosing your own post as the solution.  Especially when it isn't a solution.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.