Reputation: 2158
How do I put color coding in Linux for email for these 2 scenarios? I have looked at the other stack, they are building functions, is there any simple way to do this (without HTML) coding?
1) Job running... text in green color?
echo -e "Job running..." | mail -s "Job running..."
2) Job failing... text in red color?
echo -e "Job failing..." | mail -s "Job failing..."
Tries. echo gives on the front end, but doesn't send the color in email.
echo -e '\033[0;32m'"\033[1mJob running...\033[0m" | mail -s "Job running..." [email protected]
Thanks!
Upvotes: 0
Views: 6791
Reputation: 5232
Use the ANSI Escape Sequences (if using bash!):
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
echo -e "${GREEN}Job running...${NC}" | mail -s "Job running..."
echo -e "${RED}Job failing...${NC}" | mail -s "Job failing..."
Coloring the mail for the reciepient without using HTML is not possible. If you wish for color in the resulting mail use HTML formatting.
Upvotes: 1