LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-11-2010, 05:37 PM   #1
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Rep: Reputation: 15
Smile attach multiple file using mailto


Hello,

I am trying to set-up a script that will go to the folder and attach all files from that folder to the email without having to specify name for each attached file.

Below script requires exact name of the file and then puts file context into the emails body.

Does anyone have better script?


cd /home/denis/Test/



mail -s "log files attached" smith_denis@ymail.com <log.txt


Thanks in advance

Denis
 
Old 05-12-2010, 11:35 AM   #2
yooy
Senior Member
 
Registered: Dec 2009
Posts: 1,387

Rep: Reputation: 173Reputation: 173
not sure if it will help but seamonkey (gui) allows "drag n drop" for attachments
 
Old 05-12-2010, 11:51 AM   #3
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
With the mail program on Fedora 12, you can sent attachments like this:
Code:
mail -a /path/to/attachment -s "some subject" someone@somewhere < body.txt
If you want to attach each individual file in some directory (an alternative is to tar/zip everything), you can use something like this:
Code:
DIR=/path/to/dir
ATTACHMENT_ARGS=""

for FILE in $(find $DIR -type f); do
  ATTACHMENT_ARGS="$ATTACHMENT_ARGS -a $FILE"
done
if [ -n "$ATTACHMENT_ARGS" ]; then
  mail $ATTACHMENT_ARGS -s "some subject" someone@somewhere < /dev/null
fi
 
Old 05-12-2010, 03:16 PM   #4
smithy2010
Member
 
Registered: May 2010
Location: UK
Distribution: OpenSuse 64 bit
Posts: 45

Original Poster
Rep: Reputation: 15
Thumbs up

Hi,

Thank you very much for your time, I personalized your script little bit and it is now working just the way I wanted. I really appreciate your help.

This is the end product;


DIR=/home/denis/Logs/

ATTACHMENT_ARGS=""



for FILE in $(find $DIR -type f); do

ATTACHMENT_ARGS="$ATTACHMENT_ARGS -a $FILE"

done

if [ -n "$ATTACHMENT_ARGS" ]; then

mail $ATTACHMENT_ARGS -s "Log Files Attached" smith_denis@ymail.com < /home/denis/MailBody/emailmessagebody.txt

fi



I added this bit: /home/denis/MailBody/emailmessagebody.txt
script goes to this folder and uses content of the emailmessagebody.txt
as a email body.

Best wishes

Denis
 
Old 05-12-2010, 03:30 PM   #5
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Very good, Denis. You're welcome.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to attach file in sendmail a7mlinux Linux - General 1 05-02-2009 12:31 PM
how to attach file in forum dbmacartney LQ Suggestions & Feedback 7 04-16-2008 07:52 AM
want to attach a file with my message . nesta Programming 1 10-09-2006 11:33 AM
Help needed: attaching zip file using mailto hmacasiano Linux - Newbie 9 10-06-2005 05:21 AM
Has anyone set up cron to "mailto" multiple persons? m_cornelsen Linux - General 1 11-17-2001 08:08 AM


All times are GMT -5. The time now is 11:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration