LinuxQuestions.org
Help answer threads with 0 replies.
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 02-03-2018, 08:09 AM   #1
sniper8752
Member
 
Registered: Oct 2012
Posts: 564

Rep: Reputation: Disabled
sendmail subject and body


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

Code:
echo "Subject: alert"; echo "body stuff here" | sendmail -f "from <fromemail@mail.com>" -t "to <toemail@mail.com>"
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
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,804

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
probably this helps: https://unix.stackexchange.com/quest...-into-sendmail
 
Old 02-03-2018, 04:05 PM   #3
ftg
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
RandomTroll
Senior Member
 
Registered: Mar 2010
Distribution: Slackware
Posts: 1,953

Rep: Reputation: 270Reputation: 270Reputation: 270
I use sendmail:

Code:
echo "message body" | sendmail -f sender@mail.com -s "the subject" recipient@mail.com

'-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:

Code:
echo -e "to:  recipient@mail.com\ncc: carbon@mail.com\nbcc: blindcarbon@mail.com\n\nmessage body" | sendmail -t -f sender@mail.com -s "the subject"
 
  


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

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

All times are GMT -5. The time now is 10:15 AM.

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