我在我的Fedora12上使用Tcl和expect脚本自动执行网络切换。测试日志和结果连同附件一起发送到电子邮件收件箱(Office365)、-browser和outlook模式。
我想知道是否有一种方法可以使用TCL或shell脚本使彩色字体出现在我的电子邮件中。
例如,在发送到电子邮件的报告中,文本“通过”应以绿色粗体显示,字体“失败”必须以红色粗体显示。tput会有用吗?请帮帮忙。提前谢谢。
发布于 2013-05-29 20:32:19
下面是我用来发送邮件的一个简单脚本(您可能需要为smtp::sendmessage提供用户名/密码)
set textpart [::mime::initialize -canonical text/plain -string {Hello World}]
set htmlpart [::mime::initialize -canonical text/html -string {<font color="green">Hello World</font>}]
set tok [::mime::initialize -canonical multipart/alternative -parts [list $textpart $htmlpart] -header {From test@example.com}]
::mime::setheader $tok Subject {Hello World}
::smtp::sendmessage $tok -servers smtp.example.com -recipients recipient@example.com -originator test@example.com
::mime::finalize $tok -subordinates all一些注意事项:
multipart/mixed,(像multipart/alternative一样构建它),它的第一部分应该是消息(你的multipart/alternative),其他部分是一些more or less obscure circumstances上的attachments.发布于 2013-05-29 15:03:08
只需使用html电子邮件(带有content-type: text/html标题)和内联css来给它上色。
Passed应该是
<span style="color:green"><font color="green"></font></span>在这里,span提供样式
如果span不起作用,font会提供回退。一些电子邮件客户端可能会剥离这些内联样式。
发布于 2013-05-29 22:10:28
您要求的是两种不同的东西:电子邮件中的彩色文本和shell中的彩色文本。其他人已经回答了电子邮件部分,所以我想解决shell部分。对于终端输出,我使用term::ansi::send包。下面是一个示例:
package require cmdline
package require term::ansi::send
proc color_puts {args} {
# Parse the command line args
set options {
{bg.arg default "The background color"}
{fg.arg default "The foreground color"}
{nonewline "" "no ending new line"}
{channel.arg stdout "Which channel to write to"}
}
array set opt [cmdline::getoptions args $options]
# Set the foreground/background colors
::term::ansi::send::sda_fg$opt(fg)
::term::ansi::send::sda_bg$opt(bg)
# puts
if {$opt(nonewline)} {
puts -nonewline $opt(channel) [lindex $args end]
} else {
puts $opt(channel) [lindex $args end]
}
# Reset the foreground/background colors to default
::term::ansi::send::sda_fgdefault
::term::ansi::send::sda_bgdefault
}
#
# Test
#
puts "\n"
color_puts -nonewline -fg magenta "TEST"
color_puts -nonewline -fg blue " RESULTS"
puts "\n"
color_puts -fg green "test_001 Up/down direction movements passed"
color_puts -fg red "test_002 Left/right direction movements failed"讨论
color_puts的标志为:-bg表示背景色,-fg表示前景色,-nonewline表示禁止新行字符输出,-channel表示将输出定向到文件。term::ansi::send包。https://stackoverflow.com/questions/16807433
复制相似问题