在支持 HTML 的电子邮件中将 HTML 内容转换为纯文本



我正在使用构建失败分析器Jenkins插件,我定义了构建失败的失败原因。

现在我想存储失败原因输出并通过电子邮件发送。因此,我在使用电子邮件扩展插件的管道中遵循 -

 post {  
    failure {
        script {   
           def subject = "${env.JOB_NAME} - Build # ${env.BUILD_NUMBER}"
           def buildFailure = tm('${BUILD_FAILURE_ANALYZER}')
    emailext attachLog: false,
        body:  buildFailure,
        subject: subject,
        to: "testemail@test.com"
        }
}

在 Jenkins 的电子邮件扩展配置中,如果Default Content Type有价值Plain text (texthtml),我会得到类似电子邮件中以下内容 -

Identified problems:
* Code compilation failed Actions:
 1. Please click on below indication link to know the compilation failure
 2. Please resolve compilation errors
  * Indication 1:
    <http://localhost:9090//job/EmailPipelineCopy/15/consoleFull#1856183693ffa56480-b39d-4982-9c6e-524135dff05e>

这是我所期望的,但是如果我Default Content Type设置为 HTML (texthtml) ,在电子邮件中我会得到这样的内容 -

Identified problems: * Code compilation failed Actions: 1. Please click on below indication link to know the compilation failure

2. 请解决编译错误 * 指示 1:

这不是很好的显示,链接也不可用。我需要将Default Content Type设置为 HTML (texthtml)因为 HTML 中电子邮件中的其他内容。

有什么方法可以将此HTML内容更改为文本,以便它出现在带有链接的电子邮件中,并像Default Content Type = HTML (texthtml)一样正确对齐?

我从文本中删除了<>字符,并用<pre>标签将其包围,然后HTML按原样处理该文本。

最新更新