使用詹金斯发送电子邮件得到以下错误响应

时间:2018-07-31 11:34:09

标签: java email jenkins jenkins-pipeline

在这里我提到了电子邮件阶段 def subject =“作业$ {buildStatus}-$ {env.JOB_NAME}-构建

${env.BUILD_NUMBER}"
        echo "env variable running"
        echo "${subject}"
        def summary = "${subject}"
        echo "${summary}"
        def details = """ Your Job's build has been ${buildStatus}. Click the URL to view the build log. \n\n ${env.BUILD_URL} \n\n Sent from JustOps.io"""
        echo "${details}"

         mail to: "rajesh@cogzidel.com",
         subject: "${summary}",
         body: "${details}"

我遇到以下错误 执行成功发布条件时出错:

javax.mail.MessagingException: IOException while sending message;
  nested exception is:
    javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
    boundary="----=_Part_755_422232966.1533023412891"
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1141)
    at javax.mail.Transport.send0(Transport.java:195)
    at javax.mail.Transport.send(Transport.java:124)
    at org.jenkinsci.plugins.workflow.steps.MailStep$MailStepExecution.run(MailStep.java:142)
    at org.jenkinsci.plugins.workflow.steps.MailStep$MailStepExecution.run(MailStep.java:128)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1$1.call(SynchronousNonBlockingStepExecution.java:50)
    at hudson.security.ACL.impersonate(ACL.java:290)
    at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution$1.run(SynchronousNonBlockingStepExecution.java:47)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
    boundary="----=_Part_755_422232966.1533023412891"
    at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896)
    at javax.activation.DataHandler.writeTo(DataHandler.java:317)
    at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1476)
    at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1772)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1099)
    ... 12 more

2 个答案:

答案 0 :(得分:1)

这是由于未为mime类型配置底层JavaMail。 JavaMail 1.1.3中提供了html处理程序,但尚未为此配置mailcap文件。尝试添加以下行-

text/html;; x-java-content-handler=com.sun.mail.handlers.text_html

答案 1 :(得分:0)

在脚本化管道中,您将执行以下操作

import javax.activation.MailcapCommandMap;
import javax.activation.CommandMap;

@NonCPS
def setupMail(){
    MailcapCommandMap mc = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
    mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
    mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
    mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
    mc.addMailcap("message/rfc822;; x-java-content- handler=com.sun.mail.handlers.message_rfc822");
}

node {
    setupMail()
    mail(   from: 'jenkins@co.com', 
            replyTo: 'me@co.com', 
            to: someone@co.com,
            subject: "Hi there MIME",  
            body: "It Works!")
}

在此处https://issues.jenkins-ci.org/browse/JENKINS-53305

跟踪了错误