Visit Jeremy's Blog.
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 02-03-2018, 08:09 AM   #1
Registered: Oct 2012
Posts: 474

Rep: Reputation: Disabled
sendmail subject and body

I am trying to send an email with a subject and body. Here is what I have:

echo "Subject: alert"; echo "body stuff here" | sendmail -f "from <>" -t "to <>"
When I execute this command, it spits out "Subject: alert", and then sends the email with the body being "body stuff here".
Old 02-03-2018, 09:51 AM   #2
LQ Guru
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 13,098

Rep: Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143Reputation: 4143
probably this helps:
Old 02-03-2018, 04:05 PM   #3
LQ Newbie
Registered: Feb 2018
Posts: 1

Rep: Reputation: Disabled
Sending a subject

The first "echo" won't do what you want because the semicolon terminates the command specification (which is why you see the Subject header echoed to the terminal). The second echo provides the message body to sendmail because sendmail expects the body as its stdin, which is what the "|" pipe does.

You'd need to supply the subject to sendmail using a switch on the sendmail command line, much as you are doing for the "to" and "from".

"man sendmail" will probably get you only the syntax for running sendmail as a server, not as a client as you are doing here. Try "man mail" for the client version. For example, "mailx" uses a "-s" switch to supply the subject.
Old 02-04-2018, 10:16 AM   #4
Senior Member
Registered: Mar 2010
Distribution: Slackware
Posts: 1,286

Rep: Reputation: 218Reputation: 218Reputation: 218
I use sendmail:

echo "message body" | sendmail -f -s "the subject"

'-t' instructs sendmail to inspect the message body for recipients, not specify a recipient. This puts a recipient in the envelope, not the header, something to which many SMTP servers object. If you use -t you can put the recipients in the body:

echo -e "to:\ncc:\nbcc:\n\nmessage body" | sendmail -t -f -s "the subject"


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
Due to the animosity to undescriptive subject lines, little now is left for the body mark_alfred LQ Suggestions & Feedback 12 08-16-2009 01:01 PM
sendmail subject configuration yusufs Linux - General 8 12-06-2007 03:29 AM
Forward subject in sendmail w3bd3vil Linux - General 1 02-06-2007 07:53 AM
subject parameter for sendmail? pwtct Linux - Software 4 08-06-2004 10:58 AM
sendmail (dont just ignore it 'cause its got sendmail in the subject :P) GnomeKing Linux - Networking 1 11-12-2001 09:57 PM > Forums > Linux Forums > Linux - Newbie

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

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