Solved

How do I attach a .csv file in UNIX to an email message to send out

Posted on 2003-11-17
8
4,150 Views
Last Modified: 2007-12-19
I am attempting to use UNIX to send an email message.  With this email message I would like to send an attachment. Can this be done?  Currently I am using the following code:
mailx -s $Submsg3 $Email_Recip < ${SQL_FIL}

The problem that I am having is that the sql file is part of the body of the email and I would like it to be an attachment of the email.  Thank you for your help with this.
0
Comment
Question by:wrigh066
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 9767479
uuencode $SQL_FIL | mailx -s $Submsg3 $Email_Recip

or if you have a mail client like mutt or pine, you can MIME encode and email the attachment using their options.
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9768019
if u do not have uuencode installed then try this.
create a tar fir attachement.
tar cvf - attachment  | gzip - > attachment.tar.gz
attachment.tar.gz | mail -s "this is the subject" me@mymail.com
0
 
LVL 24

Expert Comment

by:shivsa
ID: 9768028
also read this post, u can get the code for sending attachement from here.
http://www.experts-exchange.com/Operating_Systems/Linux/Q_20786839.html
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 38

Expert Comment

by:yuzh
ID: 9768163
If you want to the Windows Mail client to get the attachment properly, use:

mpack/munpack  (MIME equivalent of uuencode/uudecode, )
or
m[un]ack - mmencode - metamail
or
mattasend
or
mutt

to send the email with attachment

eg:
echo "hello" | mutt -a file.gz -s "logs" user@address.com

http://oldlook-search.experts-exchange.com/Operating_Systems/Linux/Linux_Administration/Q_20591693.html

For Solaris you can download these tools from:
http://sunfreeware.com/
PS: for Solaris, you can also use dtmail

man mutt
man mattasend
man mpack

to learn more.

You can also use "uuencode" to do the job, but soem of the Windows mail client might not be
able to handle the attachment, you have to save the email and then transfer it to a UNIX box
to uudecode to get the attachemet.

0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9769913
to complete yuzh's comment:
  i.g. standard UNIX programs cannot create a MIME-compliant attacjment in mails, even the suggested uuencode method does not.

All mail and mailx programs I know cannot do it. Most others can, for example:

metasend -t user@some.where -s metasend -f file -b -m text/plain -e base64
pine user@some.where -attach file -I^X
elm -s ok user@some.where -A y
echo "body"| mutt -a y -s mutt user@some.where
echo "attached file: xxx.txt"|uuenview -b -a -m user@some.where -s subjet file-attachment
0
 
LVL 1

Accepted Solution

by:
mateinone earned 250 total points
ID: 9891867
uuencode can work fine

simply

uuencode test.csv test.csv|mail whoever@wherever.com

Will send any file as an attachment

you just need to check the format
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9892794
uuencode .. | mail ..
does not send attachements, except if you have a special version of mail
0
 
LVL 1

Expert Comment

by:mateinone
ID: 9979952
Then we must, and so must a fair few of our customers, as we use it on a regular basis. Also know of others doing the same thing. We were struggling with this also, eventually found the uuencode solution on a forum somewhere, and it worked a treat for us.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.

828 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