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

Convert HTML content to plain text in HTML supported email

我正在使用 Build Failure Analyzer 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 (text\html),我在电子邮件中得到如下内容 -

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 (text\html),在电子邮件中我会收到类似 -

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

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

显示效果不佳,而且链接不可用。我需要将 Default Content Type 设置为 HTML (text\html),因为 HTML 中电子邮件中的其他内容。

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

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