如何在linux中为电子邮件添加颜色编码?

时间:2016-01-26 14:02:20

标签: linux bash shell

如何在Linux中为这两种方案的电子邮件添加颜色编码?我看过另一个堆栈,它们正在构建函数,有没有简单的方法(没有HTML)编码?

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..." test@example.com

谢谢!

1 个答案:

答案 0 :(得分:1)

使用ANSI Escape序列(如果使用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..." 

在不使用HTML的情况下为收件人着色邮件可能。如果您希望在生成的邮件中使用颜色,请使用HTML格式。