List of usage examples for org.apache.commons.mail EmailAttachment ATTACHMENT
String ATTACHMENT
To view the source code for org.apache.commons.mail EmailAttachment ATTACHMENT.
Click Source Link
From source file:com.github.somi92.seecsk.util.email.EmailSender.java
public static void sendEmail(EmailContainer ec) throws RuntimeException { try {/*from www.j a va 2 s .c om*/ String user = Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL); String password = Config.vratiInstancu() .vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL_PASSWORD); EmailAttachment ea = new EmailAttachment(); ea.setPath(ec.getAttachmentPath()); ea.setDisposition(EmailAttachment.ATTACHMENT); ea.setDescription("Primer ispravno popunjene uplatnice za ?lanarinu"); ea.setName("uplatnica.pdf"); MultiPartEmail mpe = new MultiPartEmail(); mpe.setDebug(true); mpe.setAuthenticator(new DefaultAuthenticator(user, password)); mpe.setHostName( Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_HOST)); mpe.setSSLOnConnect(true); mpe.setStartTLSEnabled(true); mpe.setSslSmtpPort( Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_PORT)); mpe.setSubject(ec.getSubject()); mpe.setFrom(ec.getFromEmail(), Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_NAME)); mpe.setMsg(ec.getMessage()); mpe.addTo(ec.getToEmail()); mpe.attach(ea); mpe.send(); } catch (EmailException ex) { ex.printStackTrace(); throw new RuntimeException("Sistem nije uspeo da poalje email. Pokuajte ponovo."); } }
From source file:br.com.colmeiatecnologia.EmailMarketing.model.email.EnviaEmailAnexoModel.java
public void anexar(String caminho, String descricao, String nome) throws EmailException { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(caminho);/* w w w.ja v a 2s . c om*/ attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(descricao); attachment.setName(nome); MultiPartEmail.class.cast(email).attach(attachment); }
From source file:com.esofthead.mycollab.module.mail.FileEmailAttachmentSource.java
@Override public EmailAttachment getAttachmentObj() { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(file.getPath());//from w w w. j a va2s . c o m attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(file.getName()); return attachment; }
From source file:com.mycollab.module.mail.UrlAttachmentSource.java
@Override public EmailAttachment getAttachmentObj() { EmailAttachment attachment = new EmailAttachment(); attachment.setURL(url);//from w ww .j a v a 2s. com attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(name); return attachment; }
From source file:com.mycollab.module.mail.FileAttachmentSource.java
@Override public EmailAttachment getAttachmentObj() { EmailAttachment attachment = new EmailAttachment(); attachment.setPath(file.getPath());/*from ww w. j a v a 2s . com*/ attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName((name == null) ? file.getName() : name); return attachment; }
From source file:ec.edu.espe.distribuidas.web.ReportFacturaBean.java
public void testMultiPartEmail() throws UnsupportedEncodingException, EmailException, MalformedURLException { EmailAttachment att2 = new EmailAttachment(); att2.setPath(//from www . ja v a2 s .c om "C:\\Users\\Andres Vr\\Documents\\Git\\ProyectoMaldito7.0\\ProyectMaltido2\\ProyectoMaldito2\\ProyectoMaldito2-web\\src\\main\\webapp\\pdf\\factura.pdf"); att2.setDisposition(EmailAttachment.ATTACHMENT); att2.setDescription("Envio Factura Mantenimiento SpotLinght&Wires"); MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setSSLOnConnect(true); email.setAuthentication("spotwires@gmail.com", "084383260a"); email.addTo("avrz237@gmail.com"); email.setFrom("spotwires@gmail.com"); email.setSubject("Factura"); email.setMsg("Adjunto Factura"); email.attach(att2); email.send(); // SimpleEmail mail = new SimpleEmail(); // // //Configuracion necesaria para GMAIL // mail.setHostName("smtp.gmail.com"); // mail.setTLS(true); // mail.setSmtpPort(587); // mail.setSSL(true); // //En esta seccion colocar cuenta de usuario de Gmail y contrasea // mail.setAuthentication("spotwires@gmail.com", "084383260a"); // // //Cuenta de Email Destino // mail.addTo("avrz237@gmail.com"); // //Cuenta de Email Origen, la misma con la que nos autenticamos // mail.setFrom("spotwires@gmail.com"); // //Titulo del Email // mail.setSubject("Email enviado usando Apache Commons Email"); // //Contenido del Email // mail.setMsg("Mail enviado usando una cuenta de correo de GMAIL"); // mail.send(); }
From source file:com.vicky.common.utils.sendemail.SendEmailImpl.java
@Override public void send(Mail mail) throws Exception { try {//from ww w .j a v a2 s. com HtmlEmail htmlEmail = new HtmlEmail(); htmlEmail.setHostName(mail.getHost()); htmlEmail.setCharset(Mail.ENCODEING); htmlEmail.addTo(mail.getReceiverEmailAddress()); htmlEmail.setFrom(mail.getSenderEmailAddress(), mail.getName()); htmlEmail.setAuthentication(mail.getSenderUsername(), mail.getSenderPassword()); htmlEmail.setSubject(mail.getSubject()); htmlEmail.setMsg(mail.getMessage()); for (MailAttach mailFile : mail.getMailAttachs()) { EmailAttachment attachment = new EmailAttachment();// attachment.setPath(mailFile.getFilePath());//? //attachment.setURL(new URL("http://www.baidu.com/moumou"));//? attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(MimeUtility.encodeText(mailFile.getFileName()));//?? htmlEmail.attach(attachment);//,? } htmlEmail.send(); } catch (Exception exception) { exception.printStackTrace(); this.logger.error("toString" + exception.toString()); this.logger.error("getMessage" + exception.getMessage()); this.logger.error("exception", exception); throw new StatusMsgException( "??,??,?,?V!"); } }
From source file:br.com.spolti.tsmreport.functions.SendEmail.java
public void senderWithAttachment(String mailSender, String Subject, String msg, String dests, String smtpHost, String outputFile) throws UnknownHostException { FileOperations readFile = new FileOperations(); MultiPartEmail email = new MultiPartEmail(); EmailAttachment attachment = new EmailAttachment(); String dest_temp = dests;/*from w w w. j a v a 2s. c om*/ String[] dest = dest_temp.split(","); try { email.setHostName(smtpHost); for (int i = 0; i < dest.length; i++) { email.addTo(dest[i]); } attachment.setPath(outputFile); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(outputFile); attachment.setName("tsmreport.txt"); email.setFrom(mailSender); email.setSubject(Subject); Logger.getLogger(br.com.spolti.tsmreport.functions.SendEmail.class) .info(readFile.format2html(outputFile)); msg = msg + " \n" + readFile.format2html(outputFile); msg = msg + "Developed by Spolti (filippespolti@gmail.com), if you wanna contribute please do not hesitate. Visit https://github.com/spolti/tsmreport."; email.setMsg(msg); email.getMailSession().getProperties().setProperty("mail.smtp.localhost", "localhost"); email.attach(attachment); email.send(); Logger.getLogger(br.com.spolti.tsmreport.functions.SendEmail.class).info("----> Email sended."); } catch (Exception e) { Logger.getLogger(br.com.spolti.tsmreport.functions.SendEmail.class).error("----> Email not sended."); Logger.getLogger(br.com.spolti.tsmreport.functions.SendEmail.class).error(e); } }
From source file:com.emo.ananas.reporters.EmailReporter.java
public void report(final String reportName, final File report) { logger.info("send email report {} for {}", reportName, email); Preconditions.checkNotNull(reportName, "report name is required for email reporting"); Preconditions.checkNotNull(report, "report file is required for email reporting"); EmailAttachment attachment = new EmailAttachment(); attachment.setPath(report.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(reportName); final String extension; int i = report.getName().lastIndexOf('.'); if (i > 0) { extension = report.getName().substring(i); } else {// w ww . ja v a2s . com extension = ""; } attachment.setName(reportName + extension); MultiPartEmail email = new MultiPartEmail(); email.setHostName(sender.smtp); try { for (final String aTo : this.email.to) { email.addTo(aTo); } email.setFrom(this.email.from); email.setSubject(this.email.subject); email.setMsg("Report for " + reportName); email.attach(attachment); email.send(); } catch (EmailException e) { throw new RuntimeException("failed to send email for report " + reportName + " with " + this.email, e); } }
From source file:com.teamj.distribuidas.web.EmailSessionBean.java
public void sendEmail(String to, String subject, String body, String path) { //Email email = new SimpleEmail(); MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587);//from w w w. java 2 s. c o m email.setAuthenticator(new DefaultAuthenticator("dennysaurio", "tuclave")); // email.setSSLOnConnect(true); email.setDebug(true); //email.setStartTLSEnabled(true); try { email.getMailSession().getProperties().put("mail.smtps.auth", "true"); email.getMailSession().getProperties().put("mail.debug", "true"); email.getMailSession().getProperties().put("mail.smtps.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.port", "587"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); email.getMailSession().getProperties().put("mail.smtps.socketFactory.fallback", "false"); email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); email.getMailSession().getProperties().put("mail.smtp.ssl.trust", "smtp.gmail.com"); EmailAttachment attachment = new EmailAttachment(); // #{facesContext.externalContext.requestContextPath} attachment.setPath("D:\\IMG_20151101_213514644.jpg"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Picture of Anita"); attachment.setName("anita.jpg"); //email.setTLS(true); /** * smtp.host=smtp.gmail.com smtp.port=587 smtp.ssl=yes * props.put("mail.smtp.starttls.enable", "true"); * props.put("mail.smtp.auth", "true"); smtp.user="me@gmail.com" * smtp.password="myPassword" */ email.setFrom("dennysaurio@gmail.com"); email.setSubject(subject); email.setMsg(body); email.addTo(to); email.attach(attachment); email.send(); } catch (EmailException ex) { Logger.getLogger(EmailSessionBean.class.getName()).log(Level.SEVERE, null, ex); } }