I need to send an email from my build script. My code works perfectly as a standalone program; however, when it’s in a build script, I get an exception.
Here’s the script:
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
buildscript {
repositories {
...
}
dependencies {
classpath group: 'org.apache.commons', name: 'commons-email', version: '1.0'
classpath 'javax.mail:mail:1.4.3'
classpath 'javax.activation:activation:1.1.1'
classpath 'com.sun.mail:smtp:1.3'
}
}
task sendEmail() {
EmailAttachment attachment = new EmailAttachment()
attachment.setPath(buildDir.getPath() + "/distributions/attachment.tar.bz2")
attachment.setDisposition(EmailAttachment.ATTACHMENT)
attachment.setDescription("attachment.tar.bz2")
attachment.setName("attachment.tar.bz2")
MultiPartEmail mpe = new MultiPartEmail()
mpe.setHostName("SNIP")
mpe.addTo("SNIP")
mpe.setFrom("SNIP")
mpe.setSubject("Test Email")
mpe.setMsg("Test")
mpe.attach(attachment)
mpe.send()
}
Here’s the last bin of the exception:
Caused by: javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_1295168.1330979754288"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:930)
at org.apache.commons.mail.Email.sendMimeMessage(Email.java:863)
... 77 more
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_1295168.1330979754288"
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:888)
... 78 more