List of usage examples for org.apache.commons.mail Email addTo
public Email addTo(final String... emails) throws EmailException
From source file:edu.corgi.uco.sendEmails.java
public static void sendAdvisorCancel(String emailAddress, String studentFirstName, String studentLastName) { try {/* ww w.jav a 2 s. c o m*/ System.out.print("hit send"); Email email = new SimpleEmail(); System.out.print("created email file"); email.setDebug(true); email.setHostName("smtp.gmail.com"); email.setAuthenticator(new DefaultAuthenticator("ucocorgi2@gmail.com", "ucodrsung")); email.setStartTLSEnabled(true); email.setSmtpPort(587); email.setFrom("ucocorgi@gmail.com", "UCO CS Corgi"); email.setSubject("Advisement Update"); email.setMsg( studentFirstName + " " + studentLastName + "your appointment has been canceled by the advisor." + "You will need to log in to CORGI and sign up for another appointment to get advised." + "Thank you."); System.out.print("Email Address: " + emailAddress); email.addTo(emailAddress); System.out.print("added values"); email.send(); System.out.print("sent"); } catch (EmailException ex) { Logger.getLogger(sendEmails.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:gobblin.util.EmailUtils.java
/** * A general method for sending emails.//from ww w .j a v a 2s . c om * * @param state a {@link State} object containing configuration properties * @param subject email subject * @param message email message * @throws EmailException if there is anything wrong sending the email */ public static void sendEmail(State state, String subject, String message) throws EmailException { Email email = new SimpleEmail(); email.setHostName(state.getProp(ConfigurationKeys.EMAIL_HOST_KEY, ConfigurationKeys.DEFAULT_EMAIL_HOST)); if (state.contains(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)) { email.setSmtpPort(state.getPropAsInt(ConfigurationKeys.EMAIL_SMTP_PORT_KEY)); } email.setFrom(state.getProp(ConfigurationKeys.EMAIL_FROM_KEY)); if (state.contains(ConfigurationKeys.EMAIL_USER_KEY) && state.contains(ConfigurationKeys.EMAIL_PASSWORD_KEY)) { email.setAuthentication(state.getProp(ConfigurationKeys.EMAIL_USER_KEY), PasswordManager .getInstance(state).readPassword(state.getProp(ConfigurationKeys.EMAIL_PASSWORD_KEY))); } Iterable<String> tos = Splitter.on(',').trimResults().omitEmptyStrings() .split(state.getProp(ConfigurationKeys.EMAIL_TOS_KEY)); for (String to : tos) { email.addTo(to); } String hostName; try { hostName = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { LOGGER.error("Failed to get the host name", uhe); hostName = "unknown"; } email.setSubject(subject); String fromHostLine = String.format("This email was sent from host: %s%n%n", hostName); email.setMsg(fromHostLine + message); email.send(); }
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"); }/* ww w. jav a 2 s .com*/ 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:ch.sdi.core.impl.mail.MailSenderDefaultTest.java
/** * Test method for {@link ch.sdi.core.impl.mail.MailSenderDefault#sendMail(org.apache.commons.mail.Email)}. *///from w w w. j a v a2 s. c o m @Ignore("TODO: Provide a mocked mail sink ") @Test public void testSendMail() throws Throwable { Email email = new SimpleEmail(); email.addTo("heri@lamp.vm"); email.setSubject("Testmail"); email.setMsg("Dies ist ein Testmail"); myLog.debug("Test: sending simple mail: " + email); myClassUnderTest.sendMail(email); }
From source file:ch.sdi.core.impl.mail.MailCreator.java
/** * Creates a new simple mail class and fills the subject and the body for the given person * @param aPerson the person for whom the mail is addressed * * @return a mail instance/*ww w . j a va2 s . com*/ * @throws SdiException on any problem */ public Email createMailFor(Person<?> aPerson) throws SdiException { Email email = new SimpleEmail(); try { email.addTo(aPerson.getEMail()); String subject = myMailTextResolver.getResolvedSubject(aPerson); myLog.debug("resolved subject: " + subject); email.setSubject(subject); String body = myMailTextResolver.getResolvedBody(aPerson); myLog.debug("resolved body: " + body); email.setMsg(body); } catch (EmailException t) { throw new SdiException("Problems setting up mail for " + aPerson.getEMail(), t, SdiException.EXIT_CODE_MAIL_ERROR); } return email; }
From source file:br.com.utfpr.edu.br.agenda.ServicoMail.EnviaEmailSimpleMail.java
public void envio(String destino) { Email email = new SimpleEmail(); try {//from w ww . j a v a 2s. co m email.setSubject("Teste de Envio com Simple Mail"); email.addTo(destino); email.setMsg("Est na hora de realizar a manuteno do seu carro. Verifique os itens!"); mailer.send(email); } catch (EmailException ex) { System.out.println("Erro ao enviar com Simple Mail."); Logger.getLogger(EnviaEmailSimpleMail.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:jmockit.tutorial.domain.MyBusinessService.java
private void sendNotificationEmail(List<EntityX> items) throws EmailException { Email email = new SimpleEmail(); email.setSubject("Notification about processing of ..."); email.addTo(data.getCustomerEmail()); // Other e-mail parameters, such as the host name of the mail server, have defaults defined through external // configuration. String message = buildNotificationMessage(items); email.setMsg(message);/*from w w w.j a v a2 s . c om*/ email.send(); }
From source file:com.kylinolap.job.tools.MailService.java
public void sendMail(List<String> receivers, String subject, String content) throws IOException { Email email = new HtmlEmail(); email.setHostName(host);// w w w . ja v a 2 s . co m email.setDebug(true); try { for (String receiver : receivers) { email.addTo(receiver); } email.setFrom(sender); email.setSubject(subject); email.setCharset("UTF-8"); ((HtmlEmail) email).setHtmlMsg(content); email.send(); email.getMailSession(); System.out.println("!!"); } catch (EmailException e) { e.printStackTrace(); } }
From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java
public int sendTextEmail(EmailInfo emailInfo, String emailAddress, String subject, String content) { try {/*from w w w .jav a 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: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 w ww .j a v 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(); }