Example usage for javax.mail MessagingException MessagingException

List of usage examples for javax.mail MessagingException MessagingException

Introduction

In this page you can find the example usage for javax.mail MessagingException MessagingException.

Prototype

public MessagingException(String s, Exception e) 

Source Link

Document

Constructs a MessagingException with the specified Exception and detail message.

Usage

From source file:com.brif.nix.parser.BinaryTempFileBody.java

public InputStream getInputStream() throws MessagingException {
    try {/*from   ww w .j a va  2  s. c  om*/
        return new BinaryTempFileBodyInputStream(new FileInputStream(mFile));
    } catch (IOException ioe) {
        throw new MessagingException("Unable to open body", ioe);
    }
}

From source file:com.synyx.greetingcard.mail.OpenCmsMailService.java

public void sendMail(MessageConfig config) throws MessagingException {
    log.debug("Sending message " + config);

    Session session = getSession();/*from www .  ja v a 2s  .  c om*/
    final MimeMessage mimeMessage = new MimeMessage(session);
    try {
        mimeMessage.setFrom(new InternetAddress(config.getFrom(), config.getFromName()));
        mimeMessage.addRecipient(Message.RecipientType.TO,
                new InternetAddress(config.getTo(), config.getToName()));
    } catch (UnsupportedEncodingException ex) {
        throw new MessagingException("Setting from or to failed", ex);
    }
    mimeMessage.setSubject(config.getSubject());
    mimeMessage.setContent(config.getContent(), config.getContentType());
    // we don't send in a new Thread so that we get the Exception
    Transport.send(mimeMessage);
}

From source file:com.jrzmq.core.email.SimpleMailService.java

/**
 * ?/*from ww w.j a  va  2s.  c  o m*/
 * @param templateName        ???
 * @param map                 ?
 * @return
 * @throws MessagingException
 */
private String generateContent(String templateName, Map<String, Object> map) throws MessagingException {

    try {
        return FreeMarkerTemplateUtils.processTemplateIntoString(
                freemarkerConfiguration.getTemplate(templateName, DEFAULT_ENCODING), map);
    } catch (IOException e) {
        logger.error("?, FreeMarker??", e);
        throw new MessagingException("FreeMarker??", e);
    } catch (TemplateException e) {
        logger.error("?, FreeMarker?", e);
        throw new MessagingException("FreeMarker?", e);
    }
}

From source file:com.it.j2ee.modules.email.MimeMailService.java

/**
 * Freemarker?html?.// w w w. ja  v  a 2  s  .c om
 */
private String generateContent(String userName) throws MessagingException {

    try {
        Map context = Collections.singletonMap("userName", userName);
        return FreeMarkerTemplateUtils.processTemplateIntoString(template, context);
    } catch (IOException e) {
        logger.error("?, FreeMarker??", e);
        throw new MessagingException("FreeMarker??", e);
    } catch (TemplateException e) {
        logger.error("?, FreeMarker?", e);
        throw new MessagingException("FreeMarker?", e);
    }
}

From source file:ch.algotrader.util.mail.EmailTransformer.java

/**
 * Parses a mail message./*  w  w w  . j a va 2 s. co  m*/
 *
 * If the mail message is an instance of {@link Multipart} then we delegate
 * to {@link #handleMultipart(Multipart, List)}.
 * @throws MessagingException
 */
public void handleMessage(final javax.mail.Message mailMessage, final List<EmailFragment> emailFragments)
        throws MessagingException {

    final Object content;

    try {
        content = mailMessage.getContent();
    } catch (IOException e) {
        throw new MessagingException("error while retrieving the email contents.", e);
    }

    // only handle multi part messages
    if (content instanceof Multipart) {
        Multipart multipart = (Multipart) content;
        handleMultipart(multipart, emailFragments);
    } else {
        throw new MessagingException("message is not a multipart message");
    }
}

From source file:com.oakhole.core.email.MimeMailService.java

/**
 * ?classpath./*  ww  w.ja v a 2 s .  c o  m*/
 */
private File generateAttachment() throws MessagingException {
    try {
        Resource resource = new ClassPathResource(attachment);
        return resource.getFile();
    } catch (IOException e) {
        logger.error(",?", e);
        throw new MessagingException("?", e);
    }
}

From source file:mitm.application.djigzo.james.matchers.AbstractHeaderValueRegEx.java

@Override
public Collection<MailAddress> matchMail(Mail mail) throws MessagingException {
    try {/*from w w  w .  ja va2  s  . c o m*/
        String header = getHeader(mail);

        if (StringUtils.isNotEmpty(header)) {
            String[] headerValues = mail.getMessage().getHeader(header);

            if (headerValues != null) {
                Pattern pattern = getHeaderValuePattern(mail);

                if (pattern != null) {
                    for (String headerValue : headerValues) {
                        headerValue = HeaderUtils.decodeHeaderValue(headerValue);

                        Matcher matcher = pattern.matcher(headerValue);

                        if (matcher.find()) {
                            return onMatch(mail, matcher);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new MessagingException("Message cannot be read.", e);
    }

    return Collections.emptyList();
}

From source file:com.it.j2ee.modules.email.MimeMailService.java

/**
 * ?classpath.//from  w  ww  .j a  va  2s. co m
 */
private File generateAttachment() throws MessagingException {
    try {
        Resource resource = new ClassPathResource("/email/mailAttachment.txt");
        return resource.getFile();
    } catch (IOException e) {
        logger.error(",?", e);
        throw new MessagingException("?", e);
    }
}

From source file:mitm.application.djigzo.james.mailets.DKIMSign.java

protected static PrivateKey parseKey(String pkcs8) throws MessagingException {
    PrivateKey key = null;//  w  w w  . j a  v a 2 s. c  o m

    pkcs8 = StringUtils.trimToNull(pkcs8);

    if (pkcs8 != null) {
        PEMReader pem = new PEMReader(new StringReader(pkcs8));

        Object o;

        try {
            o = pem.readObject();
        } catch (IOException e) {
            throw new MessagingException("Unable to read PEM encoded private key", e);
        }

        if (o instanceof PrivateKey) {
            key = (PrivateKey) o;
        } else if (o instanceof KeyPair) {
            key = ((KeyPair) o).getPrivate();
        } else if (o == null) {
            throw new MessagingException("The PEM encoded blob did not return any object.");
        } else {
            throw new MessagingException("The PEM input is not a PrivateKey or KeyPair but a " + o.getClass());
        }
    }

    return key;
}

From source file:com.mylab.mail.OpenCmsMailService.java

public void sendMail(MessageConfig config) throws MessagingException {
    log.debug("Sending message " + config);

    Session session = getSession();//from   w  w  w.  j  a v a2 s  .  c  o m
    final MimeMessage mimeMessage = new MimeMessage(session);
    try {
        mimeMessage.setFrom(new InternetAddress(config.getFrom(), config.getFromName()));
        addRecipientsWhitelist(mimeMessage, config.getTo(), config.getToName(), config.getCardconfig());
    } catch (UnsupportedEncodingException ex) {
        throw new MessagingException("Setting from or to failed", ex);
    }
    mimeMessage.setSubject(config.getSubject());
    mimeMessage.setContent(config.getContent(), config.getContentType());
    // we don't send in a new Thread so that we get the Exception
    Transport.send(mimeMessage);
}