Search in sources :

Example 51 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method setRecipient.

/**
     * Set the specified type of recipients of a mime package
     *
     * @param type the recipients' type
     * @param address the email addresses of the recipients
     * @throws PackageException
     */
@PublicAtsApi
public void setRecipient(RecipientType type, String[] addresses) throws PackageException {
    try {
        // add the recipient
        InternetAddress[] address = new InternetAddress[addresses.length];
        for (int i = 0; i < addresses.length; i++) address[i] = new InternetAddress(addresses[i]);
        message.setRecipients(type.toJavamailType(), address);
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 52 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method addPart.

private void addPart(BodyPart part, int position) throws NoSuchMimePartException, PackageException {
    try {
        Object messageContent = message.getContent();
        if (messageContent instanceof MimeMultipart) {
            MimeMultipart multipartContent = (MimeMultipart) messageContent;
            int positionToInsertAt = position;
            if (position > multipartContent.getCount()) {
                positionToInsertAt = multipartContent.getCount();
            }
            multipartContent.addBodyPart(part, positionToInsertAt);
            // set back the modified content
            message.setContent(multipartContent);
            // decomposing
            try {
                message.saveChanges();
            } catch (MessagingException me) {
                throw new PackageException("Could not save message changes", me);
            }
            // we need to decompose again, as a new part has been added
            decompose();
        } else {
            // TODO: we can transform the part to MimeMultipart if desired
            throw new PackageException("Message is not multipart!");
        }
    } catch (MessagingException me) {
        throw new PackageException(me);
    } catch (IOException ioe) {
        throw new PackageException(ioe);
    }
}
Also used : MimeMultipart(javax.mail.internet.MimeMultipart) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) IOException(java.io.IOException)

Example 53 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method setRecipient.

/**
     * Set the To recipient of a mime package, the CC and BCC recipients are
     * cleared
     *
     * @param address the email address of the recipient
     * @throws PackageException
     */
@PublicAtsApi
public void setRecipient(String address) throws PackageException {
    try {
        // add the recipient
        InternetAddress inetAddress = new InternetAddress(address);
        message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.TO, new InternetAddress[] { inetAddress });
        message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.CC, new InternetAddress[] {});
        message.setRecipients(javax.mail.internet.MimeMessage.RecipientType.BCC, new InternetAddress[] {});
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) MessagingException(javax.mail.MessagingException) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 54 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class MimePackage method getAttachmentFileName.

/**
     * Get an attachment's file name
     *
     * @param partIndex
     * @return
     * @throws PackageException
     */
@PublicAtsApi
public String getAttachmentFileName(int partIndex) throws PackageException {
    // first check if there is part at this position at all
    if (partIndex >= attachmentPartIndices.size()) {
        throw new NoSuchMimePartException("No attachment at position '" + partIndex + "'");
    }
    try {
        MimePart part = getPart(attachmentPartIndices.get(partIndex));
        // get the attachment file name
        String fileName = part.getFileName();
        if (fileName == null) {
            throw new PackageException("Could not determine file name for attachment at position " + partIndex);
        }
        return fileName;
    } catch (MessagingException me) {
        throw new PackageException(me);
    }
}
Also used : MessagingException(javax.mail.MessagingException) NoSuchMimePartException(com.axway.ats.action.objects.model.NoSuchMimePartException) MimePart(javax.mail.internet.MimePart) NoSuchMimePackageException(com.axway.ats.action.objects.model.NoSuchMimePackageException) PackageException(com.axway.ats.action.objects.model.PackageException) PublicAtsApi(com.axway.ats.common.PublicAtsApi)

Example 55 with MessagingException

use of javax.mail.MessagingException in project ats-framework by Axway.

the class ImapFolder method open.

/**
     *
     * @see com.axway.ats.rbv.storage.Matchable#open()
     */
public void open() throws RbvStorageException {
    //first check if the folder is already open
    if (isOpen) {
        throw new MatchableAlreadyOpenException(getDescription() + " is already open");
    }
    try {
        isInitialPass = true;
        // create and connect to the user's imap folder
        if (!store.isConnected()) {
            store.connect(serverHost, userName, password);
            log.debug("Connected to store '" + serverHost + "' with user '" + userName + "' and password '" + password + "'");
        }
        if (folder == null || !folder.isOpen()) {
            folder = store.getFolder(folderName);
            folder.open(Folder.READ_WRITE);
        }
        allMetaDataList.clear();
        newMetaDataList.clear();
        isOpen = true;
        log.info("Opened " + getDescription());
    } catch (MessagingException me) {
        throw new RbvStorageException("Could not open " + getDescription(), me);
    }
}
Also used : MatchableAlreadyOpenException(com.axway.ats.rbv.model.MatchableAlreadyOpenException) MessagingException(javax.mail.MessagingException) RbvStorageException(com.axway.ats.rbv.model.RbvStorageException)

Aggregations

MessagingException (javax.mail.MessagingException)343 MimeMessage (javax.mail.internet.MimeMessage)135 IOException (java.io.IOException)126 InternetAddress (javax.mail.internet.InternetAddress)70 MimeMultipart (javax.mail.internet.MimeMultipart)64 MimeBodyPart (javax.mail.internet.MimeBodyPart)63 Message (javax.mail.Message)49 Properties (java.util.Properties)45 Session (javax.mail.Session)45 InputStream (java.io.InputStream)43 Date (java.util.Date)34 Address (javax.mail.Address)33 PackageException (com.axway.ats.action.objects.model.PackageException)32 ArrayList (java.util.ArrayList)32 NoSuchMimePackageException (com.axway.ats.action.objects.model.NoSuchMimePackageException)31 PublicAtsApi (com.axway.ats.common.PublicAtsApi)31 ServiceException (com.zimbra.common.service.ServiceException)30 ByteArrayInputStream (java.io.ByteArrayInputStream)26 DataHandler (javax.activation.DataHandler)25 UnsupportedEncodingException (java.io.UnsupportedEncodingException)24