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: [email protected]
From: [email protected]
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
4
  • 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. Commented Jul 27, 2018 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. Commented Jul 27, 2018 at 12:43
  • can you demonstrate a bit; what i understand: echo [email protected] echo From: [email protected] echo Subject: subject will change echo Content-Type: text/html; charset="us-ascii" Commented Jul 27, 2018 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... Commented Jul 27, 2018 at 13:22

1 Answer 1

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' [email protected] < /opt/b2bpiv/email.template

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

Sign up to request clarification or add additional context in comments.

4 Comments

is there an option to send html document in the body; i am taking a look as well on the help. thanks.
Since you're trying to do this from bash, your html file really only needs the <html> contents. Subject, To, and From are handled by /bin/mail. the content file can contain any text you want.
mail -a "Content-type: text/html" -s "subject" [email protected] < /opt/report.html Content-type: text/html: No such file or directory with -s it sends the report as txt.
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 stackoverflow.com/questions/24010230/mailx-send-html-message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.