LinuxQuestions.org
Visit Jeremy's Blog.
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 03-26-2008, 03:27 AM   #1
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Rep: Reputation: 15
Using /bin/mail command with a string for message, not a filename?


I know you can send an email with the contents from a file, e.g.:
Code:
mail -s "The subject" "to@email.com" < /home/message.txt
But how can one specify a message directly, without having to store the message in a file name?
 
Old 03-26-2008, 05:16 AM   #2
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 32
i am assuming something linke

Code:
mail -s "subject" "recipient@example.org" <<zzzMAILzzz
hello
this is my message text
with line breaks and everything :-)

enjoy
~me
zzzMAILzzz
 
Old 03-26-2008, 03:52 PM   #3
SirTristan
Member
 
Registered: Feb 2006
Distribution: GNU/Linux
Posts: 54

Original Poster
Rep: Reputation: 15
So start with double less than instead of single, specify a delimiter, enter the message line by line, and then specify the same delimiter again on a line by itself to end the message? That worked, thanks.

Is there any way to do this on one line?
 
Old 03-26-2008, 06:53 PM   #4
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,125

Rep: Reputation: 164Reputation: 164
Yes, this will send the echoed message via mail:
Code:
echo "A test message" | mail -s "Test subject" someone@somewhere.com
 
Old 03-26-2008, 09:22 PM   #5
tsg
Member
 
Registered: Mar 2008
Posts: 155

Rep: Reputation: 30
You can also do
Code:
 mail -s "Test Subject" someone@somewhere.com <<<"This is the message."
Check the bash man pages for "here documents" and "here strings".
 
  


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
strange filename/file in my /usr/bin directory M$ISBS Linux - Security 1 06-04-2006 08:55 PM
Filename string manipulation jango77 Linux - Newbie 2 03-27-2005 07:58 PM
how would i remove things froms filename.bin Paxmaster Linux - Software 3 01-27-2005 04:18 AM
/bin/mail command pk21 Linux - Software 3 11-16-2003 07:00 PM
linux command error message bash: /usr/bin/find: No such file or directory sundaram123 Linux - General 8 04-02-2002 08:18 AM


All times are GMT -5. The time now is 06:34 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