I have a sample script here I want to bold the word BOLD in the text and send through email. Tried several ways but not seems to working.

BODY="Hello. I want to BOLD this"
 echo "From: from@gmail.com"
 echo "To: to@gmail.com"
 echo "Subject: Texting"
 echo "X-Mailer: htmlmail" $VERSION
 echo "Mime-Version: 1.0"
 echo "Content-Type: text/html; charset=US-ASCII"
 print "<html><FONT COLOR=BLACK FACE="Geneva,Arial"SIZE=8><body>${BODY} </body>"

print "<html><FONT COLOR=BLACK FACE="Geneva,Arial"SIZE=10> ${BODY} </html>"
} | /usr/sbin/sendmail -t
  • Note: shell variables should be lower-case. – ctrl-alt-delor Dec 31 '19 at 17:34
  • print is a ksh/zsh builtin. In bash, use printf instead (different interface). – Stéphane Chazelas Dec 31 '19 at 17:38
  • Since you send the mail in HTML format you have to bracket BOLD with HTML tags: <b>BOLD</b>. – xenoid Dec 31 '19 at 17:51
  • A related question is unix.stackexchange.com/q/400858/5132 . – JdeBP Dec 31 '19 at 18:16
  1. you need a blank line between the email header and body.
  2. you are trying to put double quotes in a double quoted string, incorrectly.

Try this:

/usr/sbin/sendmail -t <<END_EMAIL
From: from@example.com
To: to@example.com
Subject: Texting
X-Mailer: htmlmail $version
Mime-Version: 1.0
Content-Type: text/html; charset=US-ASCII

|improve this answer|||||
  • I got it. Thank you. – lfc4lyf Dec 31 '19 at 19:51

These variables may be of use

reset_colour=$(   tput sgr0)
bold=$(           tput bold)
black=$(          tput setaf 0)
red=$(            tput setaf 1)
green=$(          tput setaf 2)
yellow=$(         tput setaf 3)
blue=$(           tput setaf 4)
magenta=$(        tput setaf 5)
cyan=$(           tput setaf 6)
white=$(          tput setaf 7)
default_colour=$( tput setaf 9)
|improve this answer|||||
  • 1
    Not in a text/html MIME body part, they aren't. (-: – JdeBP Dec 31 '19 at 18:05
  • Is this question about bash? or e-mail? – ctrl-alt-delor Jan 1 at 7:56
  • Given that it says "e-mail" in its first sentence and shows the use of the sendmail command, one can make an educated guess. (-: – JdeBP Jan 1 at 23:28
  • @JdeBP so the title Bold a text in Bash? – ctrl-alt-delor Jan 2 at 11:56
  • … is something that you should take up with the questioner, in a question comment; is something that one needs to read beyond, to the actual question; and is something that contains no implications of terminal I/O. (-: – JdeBP Jan 2 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.