@Signature public PHtmlEmail attach(Environment env, Memory content, String type, String name, String description) throws EmailException, MessagingException, IOException { InputStream is = Stream.getInputStream(env, content); try { htmlEmail.attach(new ByteArrayDataSource(is, type), name, description, EmailAttachment.ATTACHMENT); return this; } finally { Stream.closeStream(env, is); } }
/** * @param subject 主题 * @param body 内容 * @param attachment 附件 * @param recipients 收件人 */ public static HtmlEmail getHtmlEmail(String subject, String body, EmailAttachment attachment, String... recipients) { try { HtmlEmail htmlEmail = new HtmlEmail(); configEmail(subject, htmlEmail, recipients); if (body != null) htmlEmail.setHtmlMsg(body); // set the alter native message htmlEmail.setTextMsg("Your email client does not support HTML messages"); if (attachment != null) htmlEmail.attach(attachment); return htmlEmail; } catch (EmailException e) { throw new MailException("Unabled to send email", e); } }
protected void addAttachments(HtmlEmail email) throws EmailException { for(Entry<String,DataSource> entry : toAttach.entrySet()){ email.attach(entry.getValue(),entry.getKey(),""); } }
((HtmlEmail) email).attach(entry.getValue(), entry.getKey(), null);
((HtmlEmail) email).attach(entry.getValue(), entry.getKey(), null);
private void sendMultiMail(String fromEmail, String fromPasswd,String fromName, String host,List<String> toEmailList,MailMsg mailMsg){ HtmlEmail email = new HtmlEmail(); try { initEmail(email, fromEmail, fromPasswd,fromName, host, toEmailList, mailMsg); email.setHtmlMsg(mailMsg.getContent()); //添加附件 List<MailAttach> attachList = mailMsg.getAttachList(); EmailAttachment attachment = null; for (MailAttach mailAttach : attachList) { attachment = new EmailAttachment(); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(mailAttach.getName()); attachment.setDescription(mailAttach.getDescription()); attachment.setPath(mailAttach.getPath()); attachment.setURL(mailAttach.getUrl()); email.attach(attachment); } email.send(); } catch (EmailException e) { e.printStackTrace(); } }
emailAttachment.setDescription(attachment.getDescription()); emailAttachment.setPath(attachment.getFilePath()); htmlEmail.attach(emailAttachment); } else { FileDataSource dataSource = new FileDataSource(new File(attachment.getFilePath()));