List of usage examples for org.apache.commons.mail MultiPartEmail MultiPartEmail
MultiPartEmail
From source file:eu.ggnet.dwoss.mandator.api.value.Mandator.java
/** * Prepares a eMail to be send direct over the mandator smtp configuration. * The email is missing: to, subject, message and optional attachments. * * @return the email/* w w w.j av a 2 s . c o m*/ * @throws EmailException if something is wrong in the subsystem. */ public MultiPartEmail prepareDirectMail() throws EmailException { MultiPartEmail email = new MultiPartEmail(); email.setHostName(smtpConfiguration.getHostname()); email.addBcc(company.getEmail()); email.setFrom(company.getEmail(), company.getEmailName()); email.setAuthentication(smtpConfiguration.getSmtpAuthenticationUser(), smtpConfiguration.getSmtpAuthenticationPass()); email.setStartTLSEnabled(false); email.setSSLCheckServerIdentity(false); email.setSSLOnConnect(false); email.setCharset(smtpConfiguration.getCharset()); return email; }
From source file:com.client.named.RegisterPrestario.java
public void sendEmail(String senderId, String subject, String body) throws UnsupportedEncodingException, MessagingException { String myEmailId = "computo.citecvlp@gmail.com"; String myPassword = "impresora73"; try {/*from w w w. j av a 2 s. c o m*/ MultiPartEmail email = new MultiPartEmail(); email.setSmtpPort(587); email.setAuthenticator(new DefaultAuthenticator(myEmailId, myPassword)); email.setDebug(true); email.setHostName("smtp.gmail.com"); email.setFrom(myEmailId); email.setSubject("activacion cuenta laboratorio computo UABC"); email.setMsg(body); email.addTo(senderId); email.setTLS(true); /* EmailAttachment attachment = new EmailAttachment(); attachment.setPath("/Users/fahadparkar/Desktop/Fahim/tables.xlsx"); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription("Excel"); attachment.setName("tables.xlsx"); email.attach(attachment);*/ email.send(); System.out.println("Mail sent!"); } catch (EmailException e) { System.out.println("Exception :: " + e); } }
From source file:com.qwazr.library.email.EmailConnector.java
@JsonIgnore public MultiPartEmail getNewMultipartEmail(final Map<String, Object> params) throws EmailException { MultiPartEmail email = new MultiPartEmail(); generic_params(email, params);// w w w .j a v a2 s . com return email; }
From source file:binky.reportrunner.engine.utils.impl.EmailHandlerImpl.java
public void sendEmail(String destinationEmail, String fromEmail, String smtpServer, List<String> fileUrls, String jobName, String groupName) throws EmailException, IOException { // logger.debug("sending email to: " + to + " on host " + server); FileSystemHandler fs = new FileSystemHandlerImpl(); MultiPartEmail email = new MultiPartEmail(); email.setDebug(debug);//from w w w . j a v a 2 s. co m email.setHostName(smtpServer); for (String toEmail : destinationEmail.split(",")) { email.addTo(toEmail.trim()); } email.setFrom(fromEmail); email.setSubject(subject + jobName + " [" + groupName + "]"); email.setMsg("Please find attached outputs for the above job."); List<String> tempFiles = new LinkedList<String>(); for (String url : fileUrls) { EmailAttachment attachment = new EmailAttachment(); String temp = copyToTemp(url); tempFiles.add(temp); attachment.setURL(fs.getURL(temp)); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(message); // get the file name of the report from the complete path String name = fs.getFileName(url); attachment.setName(name); logger.debug("File: " + url); logger.debug("Name: " + name); email.attach(attachment); } email.send(); for (String url : tempFiles) { fs.deleteFile(url); } }
From source file:cl.alma.scrw.bpmn.tasks.MailActivityBehavior.java
protected MultiPartEmail createTextOnlyEmail(String text) { MultiPartEmail email = new MultiPartEmail(); try {/* w w w . ja v a2 s. c o m*/ email.setMsg(text); return email; } catch (EmailException e) { throw new ActivitiException("Could not create text-only email", e); } }
From source file:adams.core.net.SimpleApacheSendEmail.java
/** * Sends an email./*from w w w.j a v a 2 s . com*/ * * @param email the email to send * @return true if successfully sent * @throws Exception in case of invalid internet addresses or messaging problem */ @Override public boolean sendMail(Email email) throws Exception { org.apache.commons.mail.Email mail; String id; MultiPartEmail mpemail; EmailAttachment attachment; if (email.getAttachments().length > 0) { mail = new MultiPartEmail(); mpemail = (MultiPartEmail) mail; for (File file : email.getAttachments()) { attachment = new EmailAttachment(); attachment.setPath(file.getAbsolutePath()); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setName(file.getName()); mpemail.attach(attachment); } } else { mail = new SimpleEmail(); } mail.setFrom(email.getFrom().getValue()); for (EmailAddress address : email.getTo()) mail.addTo(address.getValue()); for (EmailAddress address : email.getCC()) mail.addCc(address.getValue()); for (EmailAddress address : email.getBCC()) mail.addBcc(address.getValue()); mail.setSubject(email.getSubject()); mail.setMsg(email.getBody()); mail.setHostName(m_Server); mail.setSmtpPort(m_Port); mail.setStartTLSEnabled(m_UseTLS); mail.setSSLOnConnect(m_UseSSL); if (m_RequiresAuth) mail.setAuthentication(m_User, m_Password.getValue()); mail.setSocketTimeout(m_Timeout); try { id = mail.send(); if (isLoggingEnabled()) getLogger().info("Message sent: " + id); } catch (Exception e) { getLogger().log(Level.SEVERE, "Failed to send email: " + mail, e); return false; } return true; }
From source file:com.commander4j.email.JeMail.java
public void postMail(String recipientsTO[], String subject, String message, String attachmentFilename, String attachmentLongFilename) throws MessagingException { logger.debug("SMTP_AUTH_REQD=" + SMTP_AUTH_REQD); logger.debug("MAIL_SMTP_HOST_NAME=" + SMTP_HOST_NAME); logger.debug("MAIL_SMTP_AUTH_USER=" + SMTP_AUTH_USER); logger.debug("MAIL_SMTP_AUTH_PWD=********"); logger.debug("MAIL_SMTP_PORT=" + MAIL_SMTP_PORT); logger.debug("MAIL_SMTP_SSL_PORT=" + MAIL_SMTP_SSL_PORT); logger.debug("MAIL_SMTP_FROM_ADRESS=" + SMTP_FROM_ADRESS); logger.debug("MAIL_SMTP_USE_SSL=" + SMTP_USE_SSL); //Email email = new SimpleEmail(); logger.debug("Creating MultiPart Email"); MultiPartEmail email = new MultiPartEmail(); logger.debug("Setting Host Name to " + SMTP_HOST_NAME); email.setHostName(SMTP_HOST_NAME);/*from w w w. j a v a 2s.c o m*/ logger.debug("Setting SMTP Port to " + MAIL_SMTP_PORT); email.setSmtpPort(Integer.valueOf(MAIL_SMTP_PORT)); logger.debug("Setting SMTP SSL Port to " + MAIL_SMTP_SSL_PORT); email.setSslSmtpPort(MAIL_SMTP_SSL_PORT); logger.debug("Setting Use SSL on Connect to " + SMTP_USE_SSL); email.setSSLOnConnect(Boolean.valueOf(SMTP_USE_SSL)); logger.debug("Authentication Required = " + SMTP_AUTH_REQD); if (SMTP_AUTH_REQD.toUpperCase().equals("TRUE")) { email.setAuthenticator(new DefaultAuthenticator(SMTP_AUTH_USER, SMTP_AUTH_PWD)); } logger.debug("Setting SMTP USE SSL = " + SMTP_USE_SSL); email.setSSLOnConnect(Boolean.valueOf(SMTP_USE_SSL)); logger.debug("Setting SMTP USE TLS = " + SMTP_USE_TLS); email.setStartTLSEnabled(Boolean.valueOf(SMTP_USE_TLS)); email.setStartTLSRequired(Boolean.valueOf(SMTP_USE_TLS)); try { logger.debug("From Address = " + SMTP_FROM_ADRESS); email.setFrom(SMTP_FROM_ADRESS); email.setSubject(subject); email.setMsg(message + "\n\n"); for (int x = 1; x <= recipientsTO.length; x++) { logger.debug("Add To Address = " + recipientsTO[x - 1]); email.addTo(recipientsTO[x - 1]); } if (JUtility.replaceNullStringwithBlank(attachmentFilename).equals("") == false) { // Create the attachment EmailAttachment attachment = new EmailAttachment(); attachment.setPath(attachmentLongFilename); attachment.setDisposition(EmailAttachment.ATTACHMENT); attachment.setDescription(attachmentFilename); attachment.setName(attachmentFilename); // add the attachment logger.debug("Add Attachment"); email.attach(attachment); } logger.debug("Sending"); email.send(); logger.debug("Sent successfully"); } catch (EmailException e) { logger.error("Unable to send email : " + e.getCause().getMessage()); } }
From source file:br.com.spolti.tsmreport.functions.SendEmail.java
public void senderWithoutAttachment(String mailSender, String Subject, String msg, String dests, String smtpHost, String outputFile) throws UnknownHostException { // FileOperations readFile = new FileOperations(); // HtmlEmail email = new HtmlEmail(); ///* ww w . j av a 2s .c om*/ // String dest_temp = dests; // String[] dest = dest_temp.split(","); // // try { // // email.setHostName(smtpHost); // for (int i = 0; i < dest.length; i++) { // email.addTo(dest[i]); // } // // email.setFrom(mailSender); // email.setSubject(Subject); // // Logger.getLogger(br.com.spolti.tsmreport.functions.SendEmail.class).info(readFile.format2html(outputFile)); // msg = "<html>" + msg + "<br><br>"; // msg = msg + " <br>" + readFile.format2html(outputFile); // msg = msg + "<br><br><br><b>Developed by Spolti, if you wanna contribute please do not hesitate.</html>"; // email.setHtmlMsg(msg); // email.getMailSession().getProperties().setProperty("mail.smtp.localhost", "localhost"); // 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); // } FileOperations readFile = new FileOperations(); MultiPartEmail email = new MultiPartEmail(); String dest_temp = dests; String[] dest = dest_temp.split(","); try { email.setHostName(smtpHost); for (int i = 0; i < dest.length; i++) { email.addTo(dest[i]); } email.setFrom(mailSender); email.setSubject(Subject); Logger.getLogger(br.com.spolti.tsmreport.functions.SendEmail.class) .info(readFile.format2html(outputFile)); msg = msg + "\n\n\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.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.dominion.salud.pedicom.negocio.tools.MAILService.java
/** * configura el ciente de correo y envia el correo con un adjunto * * @param to/*from w w w. jav a 2s .com*/ * @param attach el archivo que se adjunta en el correo * @param centro nombre del centro desde el que se envia * @throws Exception */ public void sendByMail(String to, Object attach, String centro) throws Exception { logger.debug(" Iniciando la configuracion del mail con sus parametros correspondientes ," + " obtenemos los parametros de environment"); String dataBase = routingDataSource.dbActual(); allDataSources.getDatasources(); Datasources dat = null; for (Datasources datas : allDataSources.getDatasources()) { if (datas.getNombreDatasource().equals(dataBase)) { dat = datas; break; } } if (StringUtils.isBlank(StringUtils.trim(dat.getHost()))) { throw new Exception( "El host es [" + StringUtils.trim(dat.getHost()) + "] , error de host desconocido o erroneo"); } logger.debug(" El host es [" + StringUtils.trim(dat.getHost()) + "]"); if (StringUtils.isBlank(StringUtils.trim(dat.getUsernameEmail()))) { throw new Exception("El usuario es [" + StringUtils.trim(dat.getUsernameEmail()) + "], error de login en el correo , usuario desconocido o erroneo"); } logger.debug(" El usuario es [" + StringUtils.trim(dat.getUsernameEmail()) + "]"); if (StringUtils.isBlank(StringUtils.trim(dat.getPasswordEmail()))) { throw new Exception("La contrasea es [" + StringUtils.trim(dat.getPasswordEmail()) + "], error de login en el correo , contrasea desconocida o erronea"); } logger.debug(" La contrasea es [" + StringUtils.trim(dat.getPasswordEmail()) + "]"); if (StringUtils.isBlank(to)) { throw new Exception("El destinatario es [" + to + "], no se especificaron destinatarios."); } logger.debug(" El destinatario es [" + to + "]"); /*if (dat.getPort()== null) { throw new Exception("El puerto es [" + StringUtils.trim(environment.getProperty("mail.port")) + "], el puerto del servidor de correo falla"); }*/ logger.debug(" El puerto es [" + dat.getPort() + "]"); /*if (StringUtils.isBlank(StringUtils.trim(environment.getProperty("mail.TLS")))) { throw new Exception("El TLS es [" + StringUtils.trim(environment.getProperty("mail.TLS")) + "]"); }*/ logger.debug(" El TLS es [" + dat.getTLS() + "]"); System.setProperty("mail.imap.auth.plain.disable", "true"); MultiPartEmail email = new MultiPartEmail(); email.setHostName(StringUtils.trim(dat.getHost())); email.setAuthenticator(new DefaultAuthenticator(StringUtils.trim(dat.getUsernameEmail()), StringUtils.trim(dat.getPasswordEmail()))); email.setFrom(StringUtils.trim(StringUtils.trim(dat.getUsernameEmail())), centro); email.setDebug(true); email.setSmtpPort(dat.getPort()); email.setStartTLSEnabled(dat.getTLS()); email.setSSLOnConnect(dat.getSSL()); DataSource source = null; if (attach != null) { logger.debug(" Adjuntando pdf"); source = new ByteArrayDataSource((InputStream) attach, "application/pdf"); email.attach(source, "Pedido de centro " + centro + ".pdf", "Pedido de centro " + centro); } email.setSubject("Pedido de centro [" + centro + "]"); logger.debug(" Realizando envio"); email.addTo(to); email.send(); try { if (!StringUtils.isBlank(StringUtils.trim(dat.getMailCC()))) { logger.debug(" Enviando a CC: " + dat.getMailCC()); MultiPartEmail emailCC = new MultiPartEmail(); emailCC.setHostName(StringUtils.trim(dat.getHost())); emailCC.setAuthenticator(new DefaultAuthenticator(StringUtils.trim(dat.getUsernameEmail()), StringUtils.trim(dat.getPasswordEmail()))); emailCC.setFrom(StringUtils.trim(StringUtils.trim(dat.getUsernameEmail())), centro); emailCC.setDebug(true); emailCC.setSmtpPort(dat.getPort()); emailCC.setStartTLSEnabled(dat.getTLS()); emailCC.setSSLOnConnect(dat.getSSL()); if (attach != null) { logger.debug(" Adjuntando pdf a copia"); emailCC.attach(source, "Pedido de centro " + centro + ".pdf", "Pedido de centro " + centro); } emailCC.setSubject("Pedido de centro " + centro); emailCC.addCc(StringUtils.split(StringUtils.trim(dat.getMailCC()), ",")); emailCC.send(); } } catch (Exception e) { logger.warn(" Se han producido errores al enviar los CC: " + e.toString()); } logger.debug(" Finalizando envio email"); }
From source file:emailworkshop.EmailWorkshop.java
public static void enviaEmailComAnexo(String mailFrom, String senhaFrom, String emailTo, String nomeTo) throws EmailException { // cria o anexo 1. EmailAttachment anexo1 = new EmailAttachment(); anexo1.setPath("Certificado.pdf"); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt) anexo1.setDisposition(EmailAttachment.ATTACHMENT); anexo1.setDescription("anexo"); anexo1.setName("Certificado.pdf"); // configura o email MultiPartEmail email = new MultiPartEmail(); email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail email.addTo(emailTo, nomeTo); //destinatrio email.setFrom(mailFrom, "UFPR"); // remetente email.setSubject("Certificado II Workshop de Inovao"); // assunto do e-mail email.setMsg("Segue anexo o Certificado de participaao no II Workshop, Obrigado pela presena! \n " + emailTo); //conteudo do e-mail email.setAuthentication(mailFrom, senhaFrom); email.setSmtpPort(465);//from w ww . j a v a2 s . com email.setSSL(true); email.setTLS(true); // adiciona arquivo(s) anexo(s) email.attach(anexo1); // envia o email email.send(); }