List of usage examples for org.apache.commons.mail Email send
public String send() throws EmailException
From source file:FacultyAdvisement.StudentRepository.java
public static void adminUpdate(DataSource ds, Student student, String oldUsername) throws SQLException { Connection conn = ds.getConnection(); if (conn == null) { throw new SQLException("conn is null; Can't get db connection"); }/*www.java 2 s . c o m*/ try { PreparedStatement ps; ps = conn.prepareStatement( "Update STUDENT set EMAIL=?, FIRSTNAME=?, LASTNAME=?, MAJORCODE=?, PHONE=?, ADVISED=? where STUID=?"); ps.setString(1, student.getUsername()); ps.setString(2, student.getFirstName()); ps.setString(3, student.getLastName()); ps.setString(4, student.getMajorCode()); ps.setString(5, student.getPhoneNumber()); if (student.isAdvised()) { ps.setString(6, "true"); } else { ps.setString(6, "false"); } ps.setString(7, student.getId()); ps.executeUpdate(); ps = conn.prepareStatement("Update USERTABLE set USERNAME=? where USERNAME=?"); ps.setString(1, student.getUsername()); ps.setString(2, oldUsername); ps.executeUpdate(); ps = conn.prepareStatement("Update GROUPTABLE set USERNAME=? where USERNAME=?"); ps.setString(1, student.getUsername()); ps.setString(2, oldUsername); ps.executeUpdate(); if (student.isResetPassword()) { String newPassword = UUID.randomUUID().toString(); String encryptedPassword = SHA256Encrypt.encrypt(newPassword); ps = conn.prepareStatement("Update USERTABLE set PASSWORD=? where USERNAME=?"); ps.setString(1, encryptedPassword); ps.setString(2, student.getUsername()); ps.executeUpdate(); Email email = new HtmlEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("uco.faculty.advisement", "!@#$1234")); email.setSSLOnConnect(true); email.setFrom("uco.faculty.advisement@gmail.com"); email.setSubject("UCO Faculty Advisement Password Change"); email.setMsg("<font size=\"3\">An admin has resetted your password, your new password is \"" + newPassword + "\"." + "\n<p align=\"center\">UCO Faculty Advisement</p></font>"); email.addTo(student.getUsername()); email.send(); } } catch (EmailException ex) { Logger.getLogger(StudentRepository.class.getName()).log(Level.SEVERE, null, ex); } finally { conn.close(); } //students = (HashMap<String, StudentPOJO>) readAll(); // reload the updated info }
From source file:com.webbfontaine.valuewebb.irms.action.mail.MailActionHandler.java
public void doSend(Email email) { try {/* w ww . ja v a 2 s . co m*/ email.send(); } catch (EmailException e) { LOGGER.error("", e); } }
From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java
public int sendTextEmail(EmailInfo emailInfo, String emailAddress, String subject, String content) { try {/* w w w. j a va 2 s. c o m*/ Email email = new SimpleEmail(); setBaseInfo(emailInfo, email); email.setSubject(subject); email.setMsg(content); email.addTo(emailAddress); email.send(); } catch (EmailException e) { e.printStackTrace(); return -1; } return 0; }
From source file:ch.sbb.releasetrain.utils.emails.SMTPUtilImpl.java
@Override public void send(String absender, String empfaenger, String betreff, String text) { try {/*from www . j a va 2s. com*/ final Email email = new SimpleEmail(); email.setHostName(mailhost); email.setSmtpPort(mailport); email.setFrom(absender); email.setSubject(betreff); email.setMsg(text); email.addTo(empfaenger); email.send(); log.info("mail sent to: " + empfaenger); } catch (final EmailException e) { log.error(e.getMessage(), e); } }
From source file:com.clavain.alerts.Methods.java
private static void sendMail(String title, String message, String emailaddy) { try {//from ww w . j a v a2 s . co m Email email = new SimpleEmail(); email.setHostName(p.getProperty("mailserver.host")); email.setSmtpPort(Integer.parseInt(p.getProperty("mailserver.port"))); if (p.getProperty("mailserver.useauth").equals("true")) { email.setAuthentication(p.getProperty("mailserver.user"), p.getProperty("mailserver.pass")); } if (p.getProperty("mailserver.usessl").equals("true")) { email.setSSLOnConnect(true); } else { email.setSSLOnConnect(false); } email.setFrom(p.getProperty("mailserver.from")); email.setSubject("[MuninMX] " + title); email.setMsg(message); email.addTo(emailaddy); email.send(); } catch (Exception ex) { logger.warn("Unable to send Mail: " + ex.getLocalizedMessage()); } }
From source file:com.alkacon.opencms.newsletter.CmsNewsletterMail.java
/** * Sends the newsletter mails to the recipients.<p> */// w w w . jav a 2 s. com public void sendMail() { Iterator<InternetAddress> i = getRecipients().iterator(); while (i.hasNext()) { InternetAddress to = i.next(); List<InternetAddress> toList = new ArrayList<InternetAddress>(1); toList.add(to); try { Email mail = getMailData().getEmail(); mail.setTo(toList); mail.send(); } catch (Exception e) { // log failed mail send process if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_NEWSLETTER_EMAIL_SEND_FAILED_2, to.getAddress(), getNewsletterName())); } // store message for error report mail getMailErrors() .add(Messages.get().getBundle().key(Messages.MAIL_ERROR_EMAIL_ADDRESS_1, to.getAddress())); } } }
From source file:de.cosmocode.palava.services.mail.VelocityMailService.java
@Override public MimeMessage sendMessage(String templateName, String lang, Map<String, ?> params, String... to) throws Exception { if (templateName == null) throw new IllegalArgumentException("Template name is null"); final VelocityContext ctx = new VelocityContext(params); final String prefix = StringUtils.isBlank(lang) ? "" : lang + "/"; final Template template = engine.getTemplate(prefix + templateName, CHARSET); final Embedder embed = new Embedder(engine); ctx.put("embed", embed); ctx.put("entity", EntityEncoder.getInstance()); final StringWriter writer = new StringWriter(); template.merge(ctx, writer);/*from ww w. j av a 2 s .c o m*/ final EmailFactory factory = EmailFactory.getInstance(); final SAXBuilder builder = new SAXBuilder(); final Document document = builder.build(new StringReader(writer.toString())); final Email email = factory.build(document, embed); email.setHostName(hostname); for (String recipient : to) { email.addTo(recipient); } email.send(); return email.getMimeMessage(); }
From source file:com.alkacon.opencms.v8.newsletter.CmsNewsletterMail.java
/** * Sends the newsletter mails to the recipients.<p> *//*w ww.jav a2 s.c o m*/ public void sendMail() { Iterator<InternetAddress> i = getRecipients().iterator(); int errLogCount = 0; while (i.hasNext()) { InternetAddress to = i.next(); List<InternetAddress> toList = new ArrayList<InternetAddress>(1); toList.add(to); try { Email mail = getMailData().getEmail(); mail.setTo(toList); mail.send(); } catch (Exception e) { // log failed mail send process if (LOG.isErrorEnabled()) { LOG.error(Messages.get().getBundle().key(Messages.LOG_ERROR_NEWSLETTER_EMAIL_SEND_FAILED_2, to.getAddress(), getNewsletterName())); } if (LOG.isDebugEnabled() && (errLogCount < 10)) { LOG.debug(e); errLogCount++; } // store message for error report mail String errMsg = Messages.get().getBundle().key(Messages.MAIL_ERROR_EMAIL_ADDRESS_1, to.getAddress()); if (errLogCount == 10) { errMsg += "\nStack:\n" + errMsg + "\n"; } getMailErrors().add(errMsg); } } }
From source file:ar.com.pahema.utils.MailSender.java
public static void enviar(String destino, Paquete paquete) throws EmailException { try {//from w ww.java 2 s . c o m Email mail = new SimpleEmail(); //Configuracion necesaria para GMAIL mail.setHostName("mail.pahema.com.ar"); //mail.setTLS(true); mail.setSmtpPort(25); //mail.setSSL(true); //En esta seccion colocar cuenta de usuario de Gmail y contrasea mail.setAuthentication("dante@pahema.com.ar", "Fuerza2015"); //Cuenta de Email Destino // AC? IRIA LA DE ADMINISTRACION DE PAHEMA. mail.addTo("dante.gs@hotmail.com"); mail.addTo(destino); //Cuenta de Email Origen, la misma con la que nos autenticamos mail.setFrom("dante@pahema.com.ar", "Pahema - Sistema Tango"); //Titulo del Email mail.setSubject("Aviso de finalizacin de paquete de horas."); //Contenido del Email mail.setMsg("Estimado cliente,\n" + "Le informamos que su paquete de " + (int) paquete.getCantidadHoras() + " horas est por finalizar.\n" + "Le quedan por usar: " + (int) paquete.getHorasRestantes() + " horas.\n" + "Por favor comunquese con Pahema para el detalle de sus consumos: 4952 - 4789.\n" + "Muchas gracias.\n" + "Administracin."); mail.send(); } catch (EmailException e) { System.out.println(e.getMessage()); throw new RuntimeException("Ocurrio un error en el envio del mail"); } }
From source file:gov.nih.nci.firebird.service.messages.email.EmailServiceImpl.java
private void sendEmail(Email email) throws EmailException { initEmailInfo(email);//www . ja v a2 s .c o m if (sendMail) { email.send(); } else { email.buildMimeMessage(); if (LOG.isDebugEnabled()) { LOG.debug("Email Sending is off. " + email.getMimeMessage()); } } }