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) 

Source Link

Document

Constructs a MessagingException with the specified detail message.

Usage

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

private void initErrorProcessor() throws MessagingException {
    errorProcessor = getInitParameter(Parameter.ERROR_PROCESSOR.name);

    if (StringUtils.isBlank(errorProcessor)) {
        throw new MessagingException("errorProcessor must be specified.");
    }//from   www.  j ava2 s.  co  m
}

From source file:com.adaptris.util.text.mime.MultiPartOutput.java

/**
 * Constructor.//ww w  . ja va  2s . c  o m
 * <p>
 * This implicitly sets the multipart sub-type to be mixed.
 * </p>
 * 
 * @param mimeId the Message-ID header to assign to this multi-part
 * @throws MessagingException if the bytes did not contain a valid MimeMultiPart
 */
public MultiPartOutput(String mimeId) throws MessagingException {
    this();
    if ((mimeId != null) && !mimeId.equals("")) {
        mimeHeader.setHeader(HEADER_MESSAGE_ID, mimeId);
    } else {
        throw new MessagingException("Message Id cannot be null");
    }
}

From source file:com.spartasystems.holdmail.util.TestMailClient.java

public void sendResourceEmail(String resourceName, String sender, String recipient, String subject) {

    try {/*from  w ww.java  2  s. co  m*/

        InputStream resource = TestMailClient.class.getClassLoader().getResourceAsStream(resourceName);
        if (resource == null) {
            throw new MessagingException("Couldn't find resource at: " + resourceName);
        }

        Message message = new MimeMessage(session, resource);

        // wipe out ALL exisitng recipients
        message.setRecipients(Message.RecipientType.TO, new Address[] {});
        message.setRecipients(Message.RecipientType.CC, new Address[] {});
        message.setRecipients(Message.RecipientType.BCC, new Address[] {});

        // then set the new data
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient));
        message.setFrom(InternetAddress.parse(sender)[0]);
        message.setSubject(subject);

        Transport.send(message);

        logger.info("Outgoing mail forwarded to " + recipient);

    } catch (MessagingException e) {
        throw new HoldMailException("couldn't send mail: " + e.getMessage(), e);
    }

}

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

@Override
public void init() throws MessagingException {
    getLogger().info("Initializing matcher: " + getMatcherName());

    String condition = getCondition();

    if (StringUtils.isBlank(condition)) {
        throw new MessagingException("Usage: header, value [,secret]");
    }//from  ww  w.jav a2 s  .com

    parameters = StringUtils.split(condition, ',');

    if (parameters.length < 3) {
        throw new MessagingException("Usage: header, value ,secret");
    }

    header = StringUtils.trimToNull(parameters[0]);

    if (header == null) {
        throw new MessagingException("header is missing");
    }

    value = StringUtils.trimToNull(parameters[1]);

    if (value == null) {
        throw new MessagingException("value is missing");
    }

    secret = StringUtils.trimToNull(parameters[2]);

    if (secret == null) {
        throw new MessagingException("secret is missing");
    }

    securityFactory = SecurityFactoryFactory.getSecurityFactory();
}

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

@Override
protected void initMailet() throws MessagingException {
    convertTo7Bit = getBooleanInitParameter(Parameter.CONVERT_TO_7BIT.name, true);

    foldSignature = getBooleanInitParameter(Parameter.FOLD_SIGNATURE.name, false);

    dkimHeader = getInitParameter(Parameter.DKIM_HEADER.name, DKIMCommon.DEFAULT_DKIM_HEADER);

    signatureTemplate = StringUtils.trimToNull(getInitParameter(Parameter.SIGNATURE_TEMPLATE.name));

    if (signatureTemplate == null) {
        throw new MessagingException("signatureTemplate is missing.");
    }//from w w  w  . j a v a 2s .c om

    loadPrivateKey();
}

From source file:com.sun.mail.pop3.POP3Folder.java

/**
 * Always throws <code>MessagingException</code> because no POP3 folders
 * can contain subfolders./* ww  w .j  a  va  2  s  .c om*/
 *
 * @exception   MessagingException   always
 */
public Folder[] list(String pattern) throws MessagingException {
    throw new MessagingException("not a directory");
}

From source file:com.duroty.utils.mail.MessageUtilities.java

/**
 * This wrapper is used to work around a bug in the sun io inside
 * sun.io.ByteToCharConverter.getConverterClass(). The programmer uses a
 * cute coding trick that appends the charset to a prefix to create a
 * Class name that they then attempt to load. The problem is that if the
 * charset is not one that they "recognize", and the name has something
 * like a dash character in it, the resulting Class name has an invalid
 * character in it. This results in an IllegalArgumentException instead of
 * the UnsupportedEncodingException that is documented. Thus, we need to
 * catch the undocumented exception./*from  ww w  .  j  a  v  a 2 s  .co m*/
 *
 * @param part The part from which to get the content.
 *
 * @return The content.
 *
 * @exception MessagingException if the content charset is unsupported.
 */
public static Object getPartContent(Part part) throws MessagingException {
    Object result = null;

    try {
        result = part.getContent();
    } catch (IllegalArgumentException ex) {
        throw new MessagingException("content charset is not recognized: " + ex.getMessage());
    } catch (IOException ex) {
        throw new MessagingException("getPartContent(): " + ex.getMessage());
    }

    return result;
}

From source file:MultipartViewer.java

protected Component getComponent(BodyPart bp) {

    try {/* ww w  .j  a  v a2 s.c  o  m*/
        DataHandler dh = bp.getDataHandler();
        CommandInfo ci = dh.getCommand("view");
        if (ci == null) {
            throw new MessagingException("view command failed on: " + bp.getContentType());
        }

        Object bean = dh.getBean(ci);

        if (bean instanceof Component) {
            return (Component) bean;
        } else {
            if (bean == null)
                throw new MessagingException(
                        "bean is null, class " + ci.getCommandClass() + " , command " + ci.getCommandName());
            else
                throw new MessagingException("bean is not a awt.Component" + bean.getClass().toString());
        }
    } catch (MessagingException me) {
        return new Label(me.toString());
    }
}

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

@Override
public void init() throws MessagingException {
    getLogger().info("Initializing matcher: " + getMatcherName());

    sessionManager = SystemServices.getSessionManager();

    userWorkflow = SystemServices.getUserWorkflow();

    messageOriginatorIdentifier = SystemServices.getMessageOriginatorIdentifier();

    actionExecutor = DatabaseActionExecutorBuilder.createDatabaseActionExecutor(sessionManager);

    assert (sessionManager != null);
    assert (userWorkflow != null);
    assert (messageOriginatorIdentifier != null);
    assert (actionExecutor != null);

    userProperty = getCondition();//from www .  j a v a 2  s.  co m

    if (StringUtils.isBlank(userProperty)) {
        throw new MessagingException("userProperty is missing.");
    }

    StrBuilder sb = new StrBuilder();

    sb.append("userProperty: ");
    sb.append(userProperty);

    getLogger().info(sb.toString());
}

From source file:com.seleniumtests.connectors.mails.ImapClient.java

/**
 * get list of all emails in folder//from   w w  w .  j  a v  a2s.c  o  m
 * 
 * @param folderName      folder to read
 * @param firstMessageTime   date from which we should get messages
 * @param firstMessageIndex index of the firste message to find
 * @throws MessagingException
 * @throws IOException
 */
@Override
public List<Email> getEmails(String folderName, int firstMessageIndex, LocalDateTime firstMessageTime)
        throws MessagingException, IOException {

    if (folderName == null) {
        throw new MessagingException("folder ne doit pas tre vide");
    }

    // Get folder
    Folder folder = store.getFolder(folderName);
    folder.open(Folder.READ_ONLY);

    // Get directory
    Message[] messages = folder.getMessages();

    List<Message> preFilteredMessages = new ArrayList<>();

    final LocalDateTime firstTime = firstMessageTime;

    // on filtre les message en fonction du mode de recherche
    if (searchMode == SearchMode.BY_INDEX || firstTime == null) {
        for (int i = firstMessageIndex, n = messages.length; i < n; i++) {
            preFilteredMessages.add(messages[i]);
        }
    } else {
        preFilteredMessages = Arrays.asList(folder.search(new SearchTerm() {
            private static final long serialVersionUID = 1L;

            @Override
            public boolean match(Message msg) {
                try {
                    return !msg.getReceivedDate()
                            .before(Date.from(firstTime.atZone(ZoneId.systemDefault()).toInstant()));
                } catch (MessagingException e) {
                    return false;
                }
            }
        }));

    }

    List<Email> filteredEmails = new ArrayList<>();
    lastMessageIndex = messages.length;

    for (Message message : preFilteredMessages) {

        String contentType = "";
        try {
            contentType = message.getContentType();
        } catch (MessagingException e) {
            MimeMessage msg = (MimeMessage) message;
            message = new MimeMessage(msg);
            contentType = message.getContentType();
        }

        // decode content
        String messageContent = "";
        List<String> attachments = new ArrayList<>();

        if (contentType.toLowerCase().contains("text/html")) {
            messageContent += StringEscapeUtils.unescapeHtml4(message.getContent().toString());
        } else if (contentType.toLowerCase().contains("multipart/")) {
            List<BodyPart> partList = getMessageParts((Multipart) message.getContent());

            // store content in list
            for (BodyPart part : partList) {

                String partContentType = part.getContentType().toLowerCase();
                if (partContentType.contains("text/html")) {
                    messageContent = messageContent
                            .concat(StringEscapeUtils.unescapeHtml4(part.getContent().toString()));

                } else if (partContentType.contains("text/") && !partContentType.contains("vcard")) {
                    messageContent = messageContent.concat((String) part.getContent().toString());

                } else if (partContentType.contains("image") || partContentType.contains("application/")
                        || partContentType.contains("text/x-vcard")) {
                    if (part.getFileName() != null) {
                        attachments.add(part.getFileName());
                    } else {
                        attachments.add(part.getDescription());
                    }
                } else {
                    logger.debug("type: " + part.getContentType());
                }
            }
        }

        // create a new email
        filteredEmails.add(new Email(message.getSubject(), messageContent, "",
                message.getReceivedDate().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime(),
                attachments));
    }

    folder.close(false);

    return filteredEmails;
}