0

i am using a template to send an html file in the body of an email. now what i want to do is to pass the SUBJECT of the email via command like in the shell script.

My html file looks like this:

To: test@test.com
From: noreply@test.com
Subject: subject will change
Content-Type: text/html; charset="us-ascii"
<html>
this is test email body
</html>

bash script:

email=/usr/sbin/sendmail
report=/opt/html_report.html
template=/opt/email.template

$email -t < $final_report.html
Zuntoo
  • 105
  • 10
  • open to suggestions; actually the html file and the header (first four lines) are merged using cat. the email header is saved as a template in a file and merged everytime a new html report is generated. – Zuntoo Jul 27 '18 at 12:34
  • So where does the header come from currently? You could either use sed to translate the subject to what you want, or just use echo to write out the 4 header lines direct from the shell script. – Gem Taylor Jul 27 '18 at 12:43
  • can you demonstrate a bit; what i understand: echo To=test@test.com echo From: noreply@test.com echo Subject: subject will change echo Content-Type: text/html; charset="us-ascii" – Zuntoo Jul 27 '18 at 12:48
  • `echo To: test@test,com > final.html` then `echo From: noreply@test,com >> final.html` etc. But sendmail is probably not the program you are looking for... – Gem Taylor Jul 27 '18 at 13:22

1 Answers1

2

I'm not sure the program sendmail is the one you want to use here. From the sendmail man page:

Sendmail is not intended as a user interface routine; other programs provide user-friendly front ends; sendmail is used only to deliver pre-formatted messages.

You probably want to use /bin/mail like this:

$ mail -s 'insert subject here' recipient@random.com < /opt/b2bpiv/email.template

Typing man mail or mail --help should list all the command-line options you'll need.

Don't Panic
  • 13,965
  • 5
  • 32
  • 51
ineedjava
  • 36
  • 1
  • is there an option to send html document in the body; i am taking a look as well on the help. thanks. – Zuntoo Jul 27 '18 at 12:51
  • Since you're trying to do this from bash, your html file really only needs the contents. Subject, To, and From are handled by /bin/mail. the content file can contain any text you want. – ineedjava Jul 27 '18 at 12:57
  • mail -a "Content-type: text/html" -s "subject" test@test.com < /opt/report.html Content-type: text/html: No such file or directory with -s it sends the report as txt. – Zuntoo Jul 27 '18 at 14:07
  • My version of the 'mail' command uses -a for attachments, and it looks like yours is the same (hence the 'No such file or directory') . I usually only use command line mail for text-only stuff, but you might find that mutt (another command line email client) will do what you need. See Wakaru44's answer to https://stackoverflow.com/questions/24010230/mailx-send-html-message – ineedjava Jul 27 '18 at 16:05