Search in sources :

Example 1 with MailcapCommandMap

use of javax.activation.MailcapCommandMap in project AuthMeReloaded by AuthMe.

the class SendMailSsl method sendEmail.

/**
     * Sets the given content to the HtmlEmail object and sends it.
     *
     * @param content the content to set
     * @param email the email object to send
     * @return true upon success, false otherwise
     */
public boolean sendEmail(String content, HtmlEmail email) {
    Thread.currentThread().setContextClassLoader(SendMailSsl.class.getClassLoader());
    // Issue #999: Prevent UnsupportedDataTypeException: no object DCH for MIME type multipart/alternative
    // cf. http://stackoverflow.com/questions/21856211/unsupporteddatatypeexception-no-object-dch-for-mime-type
    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");
    try {
        email.setHtmlMsg(content);
        email.setTextMsg(content);
    } catch (EmailException e) {
        ConsoleLogger.logException("Your email.html config contains an error and cannot be sent:", e);
        return false;
    }
    try {
        email.send();
        return true;
    } catch (EmailException e) {
        ConsoleLogger.logException("Failed to send a mail to " + email.getToAddresses() + ":", e);
        return false;
    }
}
Also used : MailcapCommandMap(javax.activation.MailcapCommandMap) EmailException(org.apache.commons.mail.EmailException)

Example 2 with MailcapCommandMap

use of javax.activation.MailcapCommandMap in project jdk8u_jdk by JetBrains.

the class MailTest method workaroundJAFSetup.

// this is how the error can be worked around ...
static void workaroundJAFSetup() {
    MailcapCommandMap mailMap = (MailcapCommandMap) CommandMap.getDefaultCommandMap();
    mailMap.addMailcap("multipart/mixed;;x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
}
Also used : MailcapCommandMap(javax.activation.MailcapCommandMap)

Aggregations

MailcapCommandMap (javax.activation.MailcapCommandMap)2 EmailException (org.apache.commons.mail.EmailException)1