EmailAttachment attachment = new EmailAttachment(); attachment.setPath(filepath); attachment.setDisposition(EmailAttachment.ATTACHMENT); email.attach(attachment);
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(pdfFile.getPath()); attachment.setDisposition(EmailAttachment.ATTACHMENT);
EmailAttachment attachment = new EmailAttachment(); String filePath = "pathtofile"; attachment.setPath(filePath); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("description for this attachment"); email.attach(attachment);
private EmailAttachment makeAttachment(String att) { EmailAttachment r = new EmailAttachment(); r.setDisposition(EmailAttachment.ATTACHMENT); URL url = null; try { url = new URL(att); if (StringUtils.startsWithIgnoreCase(url.getProtocol(), "file")) { r.setPath(url.getPath()); } else { r.setURL(url); } } catch (MalformedURLException e) { r.setPath(att); } r.setName(FilenameUtils.getName(att)); return r; }
public void sendWebAttachEmail(String toEmail, String toName, String subject, String msg, List attachments) throws Exception { try { MultiPartEmail email = new MultiPartEmail(); this.setEmail(email, toEmail, toName, subject, msg, null, null); for (int i = 0; i < attachments.size(); i++) { String attachPath = (String) attachments.get(i); String attachName = attachPath.substring(attachPath .lastIndexOf("/"), attachPath.length()); EmailAttachment attachment = new EmailAttachment(); attachment.setURL(new URL(attachPath)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName); email.attach(attachment); } email.send(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
public void sendWebAttachEmails(Map toEmails, String subject, String msg, List attachments) throws Exception { try { MultiPartEmail email = new MultiPartEmail(); this.setEmail(email, toEmails, subject, msg); for (int i = 0; i < attachments.size(); i++) { String attachPath = (String) attachments.get(i); String attachName = attachPath.substring(attachPath .lastIndexOf("/"), attachPath.length()); EmailAttachment attachment = new EmailAttachment(); attachment.setURL(new URL(attachPath)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName); email.attach(attachment); } email.send(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
public void sendAttachEmail(String toEmail, String toName, String subject, String msg, List attachments) throws Exception { try { MultiPartEmail email = new MultiPartEmail(); this.setEmail(email, toEmail, toName, subject, msg, null, null); for (int i = 0; i < attachments.size(); i++) { String attachPath = (String) attachments.get(i); String attachName = attachPath.substring(attachPath .lastIndexOf("/"), attachPath.length()); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachPath); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName); email.attach(attachment); } email.send(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
public void sendAttachEmails(Map toEmails, String subject, String msg, List attachments) throws Exception { try { MultiPartEmail email = new MultiPartEmail(); this.setEmail(email, toEmails, subject, msg); for (int i = 0; i < attachments.size(); i++) { String attachPath = (String) attachments.get(i); String attachName = attachPath.substring(attachPath .lastIndexOf("/"), attachPath.length()); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachPath); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName); email.attach(attachment); } email.send(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); throw e; } }
// Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(zipFile); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Zip File"); attachment.setName("myfiles.zip"); MultiPartEmail email = new MultiPartEmail(); email.attach(attachment);
EmailAttachment attachment = new EmailAttachment(); attachment.setURL(new URL(attachPath)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName);
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachPath); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName);
@Test public void testGetSetDisposition() { for (final String validChar : testCharsValid) { attachment.setDisposition(validChar); assertEquals(validChar, attachment.getDisposition()); } }
EmailAttachment attachment = new EmailAttachment(); attachment.setURL(new URL(attachPath)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName);
EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachPath); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachName); attachment.setName(attachName);
attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Excel"); attachment.setName("tables.xlsx");
ValueMap props = ResourceUtil.getValueMap(resource); HtmlEmail email = new HtmlEmail(); String[] mailTo = props.get("mailto", new String[0]); email.setFrom((String)props.get("from")); for (String toAddr : mailTo) { email.addTo(toAddr); } //========Email Attachments=============== for (Map.Entry<String, RequestParameter[]> param : slingRequest.getRequestParameterMap().entrySet()) { RequestParameter rpm = param.getValue()[0]; if(!rpm.isFormField()) { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(rpm.getFileName()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Any Description"); attachment.setName("Any name you can set"); email.embed(new ByteArrayDataSource(rpm.get(), rpm.getContentType()), rpm.getFileName()); } } //========Email Attachment END=========== String emailTextToSend = "<p>Name: " + slingRequest.getParameter("name") + "</p>"; emailTextToSend += "<p>Message: " + slingRequest.getParameter("message") + "</p>"; email.setHtmlMsg(emailTextToSend); email.setSubject((String)props.get("subject")); MessageGatewayService messageGatewayService = sling.getService(MessageGatewayService.class); MessageGateway messageGateway = messageGatewayService.getGateway(HtmlEmail.class); messageGateway.send(email);
attachment.setDisposition(EmailAttachment.ATTACHMENT); email.attach(attachment);
public static void main(String[] args) throws EmailException { // 创建附件 EmailAttachment attachment = new EmailAttachment(); attachment.setPath("mypictures/john.jpg"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Picture of John"); attachment.setName("John"); // 创建 Email Message MultiPartEmail email = new MultiPartEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("The picture"); email.setMsg("Here is the picture you wanted"); // 追加附件 email.attach(attachment); // 发送 email.send(); } }
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(); } }
attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName("Test_Attachment"); attachment.setDescription("Test Attachment Desc");