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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations