Email email = new SimpleEmail();
if(attachmentUrl!=null) {
// Create the attachment
try {
email = new MultiPartEmail();
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL(attachmentUrl));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setName("Attachment");
((MultiPartEmail) email).attach(attachment);
} catch (MalformedURLException e) {
logger.error("Invalid attachment url.", e);
} catch (EmailException e) {
logger.error("Error adding attachment to email.", e);