Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-31-2015, 04:04 AM   #1
LQ Newbie
Registered: Dec 2015
Posts: 2

Rep: Reputation: Disabled
How to specify recipients in a file and send mail using "mail -t" option

I want to specify the recipients and the subject to a file and mail program can read this info from this file.
From man pages I read that "-t" option is used:

"The message to be sent is expected to contain a message header with 'To:', 'Cc:', or 'Bcc:' fields giving its recipients.
Recipients specified on the command line are ignored."

I specify the recipients in the file as below:

[root@suitecrm ~]# cat example


Hi, this is my message, and I'm sending it to you!
[root@suitecrm ~]#

and I give the command:
[root@suitecrm ~]# mail -s test -q example -t <<<EOF

but it does not read the recipients:

[root@suitecrm ~]# mail -s test -q example -t <<<EOF
No recipients specified
"/root/dead.letter" 14/286
[root@suitecrm ~]#

Please help me how to configure the recipients in the file.

Thank you
Old 12-31-2015, 11:17 AM   #2
Senior Member
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,842

Rep: Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472Reputation: 1472
What works is giving it a body.

I think the error is coming from an EOF occurring too soon in the data stream, causing mail to not parse the data. It works if you give a blank line before the EOF.

try using:
echo "" | mail -s test -q example -t
This adds a blank line to the data (which appears to get stripped off in parsing). You can also do this in a script with a here stream following.

PS: it took several tests to figure out what the issue was. Mail is handled in stanzas - the addressing is a block, then the body is a sequence of blocks... What I THINK is being misinterpreted is that the stanza gets separated by a blank line. Once the file from the -q is loaded it doesn't interpret the EOF of that file as the end of the stanza containing the body - and an immediate EOF causes a parsing failure. This does allow for things like standard headers and body, then appending a custom body to the message (as in a here document, or adding a report file as the rest of the body through redirecting stdin).

Last edited by jpollard; 12-31-2015 at 11:25 AM.
1 members found this post helpful.
Old 01-04-2016, 04:24 AM   #3
LQ Newbie
Registered: Dec 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Hi jpollard,
It works perfectly. Thank you for your understandable explanation.



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
Need a shell script to read log file and send mail to relevant recipients. gajanan Linux - Enterprise 2 09-07-2012 01:12 AM
[SOLVED] how to send mail in sled system by "mail" richard_wu0313 Linux - Software 2 11-09-2011 06:49 PM
Shel script mail send ("/" in mail address) problem anaid Linux - Networking 3 08-23-2005 07:41 AM
Evolution 1.4 : Cannot send mail ("No recipients defined") Obi-Wan_Kenobi Linux - Software 3 11-25-2003 02:47 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:09 AM.

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