[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Unix  shell script

Posted on 2014-08-18
16
Medium Priority
?
463 Views
Last Modified: 2014-09-03
How to send email with attachement through unix shell script ?
0
Comment
Question by:digs developer
9 Comments
 
LVL 78

Accepted Solution

by:
slightwv (䄆 Netminder) earned 2000 total points
ID: 40267771
Same mailx command from your previous question but with one new twist:

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

Author Comment

by:digs developer
ID: 40267804
Could you please tell me where is the attached file syntax and how can I attcahed the test.txt file.
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40267813
>>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
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 40

Expert Comment

by:omarfarid
ID: 40268367
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
0
 
LVL 35

Expert Comment

by:johnsone
ID: 40268499
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.
0
 

Author Comment

by:digs developer
ID: 40277120
Thank you !
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40277384
>>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.
0
 

Author Comment

by:digs developer
ID: 40298757
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 !!
0
 
LVL 78

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40298758
I have to again object to choosing your own post as the solution.  Especially when it isn't a solution.
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses
Course of the Month19 days, 8 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question