We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Need to attach files to email in ksh

LuckyLucks
LuckyLucks asked
on
Medium Priority
596 Views
Last Modified: 2013-12-26
hi:

I need to attach two files -  .xls and .html extensions - to an email. I have the following code :

mail -s "Files for the month" tom.dick@harry.com < file1.html
How can I accomplish this?
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:

Hi,
you could  'mutt', which has the builtin capability of sending attachments (using MIME) -

echo "This is a body text" | mutt -a file1.html -s "Files for the month" tom.dick@harry.com
mutt can send CC (-c option) and BCC (-b option), too.
wmp
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
... with two files (sorry, saw that requirement too late)
echo "This is a body text" | mutt -a file1.html -a file2.xls -s "Files for the month" tom.dick@harry.com
CERTIFIED EXPERT
Top Expert 2007

Commented:
if you have zip command then try

zip myattachment.zip *.xls *.html
uuencode myattachment.zip myattachment.zip | mail -s "Files for the month" tom.dick@harry.com

Author

Commented:
woolmilkproc:

I am getting mutt not found. I guess we do not have this mail client. Can we accomlish the same with mail?
CERTIFIED EXPERT
Top Expert 2007

Commented:
what os do you run?
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
What is your OS? You can get mutt for almost any platform!

Author

Commented:
unix aix
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
OK,
find mutt on the AIX toolbox CD which came with your system, or here
http://www-03.ibm.com/systems/power/software/
Just click 'Alphabetical ...', download mutt and install with 'rpm -i ...'
wmp
 
 
 

Author

Commented:
I can not download softwares onto the AIX boxes. This is administered by admins and they will likely not install anything on my profile or company wide. Any other idea?


BTW omar I dont have zip either.
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
OK,

so you will have to rely on uuencode and e.g. 'tar'

tar -cvf monthfiles.tar file1.xls file2.html
uuencode monthfiles.tar monthfiles.tar | mail -s "Files for the month" tom.dick@harry.com

Note however, that 'tar' must exist at the target system!


Author

Commented:
Can I add a body test by expanding it as :

tar -cvf monthfiles.tar file1.xls file2.html
uuencode monthfiles.tar monthfiles.tar | mail -s "Files for the month" -b "Please open the attachment with winzip.\n Contents include three files: 1) file1 2) file2"  tom.dick@harry.com
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
There is no -b flag with 'mail'
What is it supposed to do? Make up a body? That's unfortunately not possible.
What you could try (I never used it and have no time to test now -

tar -cvf monthfiles.tar file1.xls file2.html
uuencode monthfiles.tar monthfiles.tar  > attach.txt
echo "Please open the attachment with winzip.\n Contents include three files: 1) file1 2) file2" > body.txt
cat body.txt attach.txt | mail -s "Files for the month" tom.dick@harry.com
wmp

Author

Commented:
Tis doesnt attach the attachment i.e attach.txt , simply sends out an email with the bosy
CERTIFIED EXPERT
Top Expert 2007
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*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.