use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method getRecipients.
/**
* Get the recipients of the specified type
*
* @param recipientType
* the type of recipient - to, cc or bcc
* @return array with recipients, emtpy array of no recipients of this type
* are present
* @throws PackageException
*/
@PublicAtsApi
public String[] getRecipients(RecipientType recipientType) throws PackageException {
try {
Address[] recipientAddresses = message.getRecipients(recipientType.toJavamailType());
// return an empty string if no recipients are present
if (recipientAddresses == null) {
return new String[] {};
}
String[] recipients = new String[recipientAddresses.length];
for (int i = 0; i < recipientAddresses.length; i++) {
recipients[i] = recipientAddresses[i].toString();
}
return recipients;
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method addAlternativePart.
/**
* Add a multipart/alternative part to message body
*
* @param plainContent
* the content of the text/plain sub-part
* @param htmlContent
* the content of the text/html sub-part
* @param charset
* the character set for the part
* @throws PackageException
*/
@PublicAtsApi
public void addAlternativePart(String plainContent, String htmlContent, String charset) throws PackageException {
MimeMultipart alternativePart = new MimeMultipart("alternative");
try {
// create a new text/plain part
MimeBodyPart plainPart = new MimeBodyPart();
plainPart.setText(plainContent, charset, PART_TYPE_TEXT_PLAIN);
plainPart.setDisposition(MimeBodyPart.INLINE);
MimeBodyPart htmlPart = new MimeBodyPart();
htmlPart.setText(htmlContent, charset, PART_TYPE_TEXT_HTML);
htmlPart.setDisposition(MimeBodyPart.INLINE);
alternativePart.addBodyPart(plainPart, 0);
alternativePart.addBodyPart(htmlPart, 1);
MimeBodyPart mimePart = new MimeBodyPart();
mimePart.setContent(alternativePart);
addPart(mimePart, PART_POSITION_LAST);
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method addRecipient.
/**
* Add recipients of a specified type
*
* @param type the recipients' type
* @param addresses the email addresses of the recipients
* @throws PackageException
*/
@PublicAtsApi
public void addRecipient(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.addRecipients(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 getPartHeader.
/**
* Get the specified header value from a specified MIME part
*
* @param headerName
* @param partNum
* @param headerIndex
* @return
* @throws PackageException
*/
@PublicAtsApi
public String getPartHeader(String headerName, int partNum, int headerIndex) throws PackageException {
try {
String[] headers;
if (partNum >= parts.size()) {
throw new NoSuchMimePartException("No MIME part at position '" + partNum + "'");
}
MimePart part = parts.get(partNum);
headers = part.getHeader(headerName);
if ((headers != null) && (headers.length > headerIndex)) {
return headers[headerIndex];
} else {
throw new NoSuchHeaderException(headerName, partNum, headerIndex);
}
} catch (MessagingException me) {
throw new PackageException(me);
}
}
use of javax.mail.MessagingException in project ats-framework by Axway.
the class MimePackage method getRegularPartContentType.
/**
* Get the content type of a regular part
*
* @param partIndex
* the index of the regular part
* @return the content type as string
* @throws PackageException
*/
@PublicAtsApi
public String getRegularPartContentType(int partIndex) throws PackageException {
// first check if there is part at this position at all
if (partIndex >= regularPartIndices.size()) {
throw new NoSuchMimePartException("No regular part at position '" + partIndex + "'");
}
try {
MimePart part = getPart(regularPartIndices.get(partIndex));
// get the content type header
ContentType contentType = new ContentType(part.getContentType());
return contentType.getBaseType();
} catch (MessagingException me) {
throw new PackageException(me);
}
}
Aggregations