List of usage examples for org.apache.commons.mail EmailAttachment getDescription
public String getDescription()
From source file:org.agnitas.util.ImportUtils.java
public static boolean sendEmailWithAttachments(String from, String fromName, String to, String subject, String message, EmailAttachment[] attachments) { boolean result = true; try {//from www .j a va 2s .co m // Create the email message MultiPartEmail email = new MultiPartEmail(); email.setCharset("UTF-8"); email.setHostName(AgnUtils.getDefaultValue("system.mail.host")); email.addTo(to); if (fromName == null || fromName.equals("")) email.setFrom(from); else email.setFrom(from, fromName); email.setSubject(subject); email.setMsg(message); //bounces and reply forwarded to support@agnitas.de String replyName = AgnUtils.getDefaultValue("import.report.replyTo.name"); if (replyName == null || replyName.equals("")) email.addReplyTo(AgnUtils.getDefaultValue("import.report.replyTo.address")); else email.addReplyTo(AgnUtils.getDefaultValue("import.report.replyTo.address"), replyName); email.setBounceAddress(AgnUtils.getDefaultValue("import.report.bounce")); // Create and attach attachments for (EmailAttachment attachment : attachments) { ByteArrayDataSource dataSource = new ByteArrayDataSource(attachment.getData(), attachment.getType()); email.attach(dataSource, attachment.getName(), attachment.getDescription()); } // send the email email.send(); } catch (Exception e) { AgnUtils.logger().error("sendEmailAttachment: " + e.getMessage()); result = false; } return result; }