LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-31-2015, 04:04 AM   #1
mkolici
LQ Newbie
 
Registered: Dec 2015
Posts: 2

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


Hi,
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

From: me@myhost.com
To: user@example.com

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
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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:
Code:
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
mkolici
LQ Newbie
 
Registered: Dec 2015
Posts: 2

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

Regards
Mikel
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:18 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
Open Source Consulting | Domain Registration