Send Email Attachments

Any other programming language that is not covered in the Web Scripting category.

Send Email Attachments

Postby hannahbrian on Fri Apr 14, 2006 5:25 pm

For the Unix/Linux programmers:

Using the "uuencode" command, you can send files through email as an attachment.

Here are some examples:
Code: Select all
ls -l > test.txt   #This creates a test file
uuencode test.txt test.txt | mail -s "Test File" [email protected]

That will send an email, with an text attachment.

Howabout this:

Code: Select all
ls -l | awk '{print $6","$7","$8","$9}' > test.csv #Makes a comma separated file
uuencode test.csv test.csv | mail -s "Test File" [email protected]

When you open the attachment from this email, it will open it up as an excel spreadsheet - very handy when you want to send comma delmited files to your email address - you could use this to send yourself a spreadsheet each day of new users to your site, or any other reports that are too long to put in the body of an email, etc.

In the previous 2 examples, the emails only contain an attachment, and no body. Here's how to send an email with a body as well:
Code: Select all
ls -l > test.txt
uuencode test.txt test.txt > MyTempFile
echo 'Here is the body' >> MyTempFile
cat MyTempFile | mail -s "Test File" [email protected]


This email will contain a message in the body, as well as an attachment.

Hope this helps someone - I use it in a few of my cron jobs.
hannahbrian
Newbie
Newbie
 
Posts: 12
Joined: Tue Mar 28, 2006 8:32 pm

Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron