List of usage examples for org.apache.commons.mail Email setHostName
public void setHostName(final String aHostName)
From source file:com.cws.esolutions.security.quartz.PasswordExpirationNotifier.java
/** * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) *//*from ww w. ja va 2s. c om*/ public void execute(final JobExecutionContext context) { final String methodName = PasswordExpirationNotifier.CNAME + "#execute(final JobExecutionContext jobContext)"; if (DEBUG) { DEBUGGER.debug(methodName); DEBUGGER.debug("JobExecutionContext: {}", context); } final Map<String, Object> jobData = context.getJobDetail().getJobDataMap(); if (DEBUG) { DEBUGGER.debug("jobData: {}", jobData); } try { UserManager manager = UserManagerFactory .getUserManager(bean.getConfigData().getSecurityConfig().getUserManager()); if (DEBUG) { DEBUGGER.debug("UserManager: {}", manager); } List<String[]> accounts = manager.listUserAccounts(); if (DEBUG) { DEBUGGER.debug("accounts: {}", accounts); } if ((accounts == null) || (accounts.size() == 0)) { return; } Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 30); Long expiryTime = cal.getTimeInMillis(); if (DEBUG) { DEBUGGER.debug("Calendar: {}", cal); DEBUGGER.debug("expiryTime: {}", expiryTime); } for (String[] account : accounts) { if (DEBUG) { DEBUGGER.debug("Account: {}", (Object) account); } List<Object> accountDetail = manager.loadUserAccount(account[0]); if (DEBUG) { DEBUGGER.debug("List<Object>: {}", accountDetail); } try { Email email = new SimpleEmail(); email.setHostName((String) jobData.get("mailHost")); email.setSmtpPort(Integer.parseInt((String) jobData.get("portNumber"))); if ((Boolean) jobData.get("isSecure")) { email.setSSLOnConnect(true); } if ((Boolean) jobData.get("isAuthenticated")) { email.setAuthenticator(new DefaultAuthenticator((String) jobData.get("username"), PasswordUtils.decryptText((String) (String) jobData.get("password"), (String) jobData.get("salt"), secConfig.getSecretAlgorithm(), secConfig.getIterations(), secConfig.getKeyBits(), secConfig.getEncryptionAlgorithm(), secConfig.getEncryptionInstance(), systemConfig.getEncoding()))); } email.setFrom((String) jobData.get("emailAddr")); email.addTo((String) accountDetail.get(6)); email.setSubject((String) jobData.get("messageSubject")); email.setMsg(String.format((String) jobData.get("messageBody"), (String) accountDetail.get(4))); if (DEBUG) { DEBUGGER.debug("SimpleEmail: {}", email); } email.send(); } catch (EmailException ex) { ERROR_RECORDER.error(ex.getMessage(), ex); } catch (SecurityException sx) { ERROR_RECORDER.error(sx.getMessage(), sx); } } } catch (UserManagementException umx) { ERROR_RECORDER.error(umx.getMessage(), umx); } }
From source file:edu.br.tcc.ManagedBean.TrabalhosBean.java
public Formulario enviarEmail(Formulario trabalho) { System.out.println("entrou no metodo do mb enviarEmail"); try {/*from ww w. ja va 2 s . c om*/ System.out.println("teste: " + trabalho.getEmail()); Email emailSimples = new SimpleEmail(); emailSimples.setHostName("smtp.live.com"); emailSimples.setStartTLSEnabled(true); emailSimples.setSmtpPort(587); emailSimples.setDebug(true); emailSimples.setAuthenticator(new DefaultAuthenticator("Seu email outlook", "sua senha")); emailSimples.setFrom("Seu email outlook"); emailSimples.setSubject(formulario.getAssunto()); emailSimples.setMsg(formulario.getTexto() + " " + caminho2 + trabalho.getMatricula() + ".docx"); emailSimples.addTo(trabalho.getEmail()); emailSimples.send(); } catch (EmailException ex) { // System.out.println(""+ex); Logger.getLogger(FormularioDAO.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:edu.corgi.uco.sendEmails.java
public String send(String emailAddress, String studentFirstName, String studentLastName) throws EmailException { System.out.print("hit send"); Email email = new SimpleEmail(); System.out.print("created email file"); email.setDebug(true);/*w ww . j av a2s . co m*/ 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 Secretary"); email.setSubject("Advisement Update"); email.setMsg(studentFirstName + " " + studentLastName + " your advisment has been processed and the hold on your account will be removed shortly"); System.out.print("Email Address: " + emailAddress); email.addTo(emailAddress); System.out.print("added values"); email.send(); System.out.print("sent"); return null; }
From source file:com.northernwall.hadrian.workItem.email.EmailWorkItemSender.java
private void emailWorkItem(String subject, String body) { try {//from w w w . j av a 2 s . c o m if (emailTos.isEmpty()) { return; } Email email = new SimpleEmail(); if (smtpHostname != null) { email.setHostName(smtpHostname); } email.setSmtpPort(smtpPort); if (smtpUsername != null && smtpPassword != null) { email.setAuthenticator(new DefaultAuthenticator(smtpUsername, smtpPassword)); } email.setSSLOnConnect(smtpSsl); email.setFrom(emailFrom); email.setSubject(subject); email.setMsg(body); for (String emailTo : emailTos) { email.addTo(emailTo); } email.send(); if (emailTos.size() == 1) { logger.info("Emailing work item to {} with subject {}", emailTos.get(0), subject); } else { logger.info("Emailing work item to {} and {} other email addresses with subject {}", emailTos.get(0), (emailTos.size() - 1), subject); } } catch (EmailException ex) { throw new RuntimeException("Failure emailing work item, {}", ex); } }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Sends a password reset email to the email address provided * /* w ww . j a va 2 s . com*/ * @param toEmail * @param newPwd * @throws Exception */ public void sendPwdResetMailFromApp(String toEmail, String newPwd) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Reset Olhie Password"); email.setMsg("You have requested that your password be reset. Your new Olhie password is " + newPwd); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * Author Request email that goes to the olhie administrator * //ww w.j a v a2 s .co m * @param toEmail * @param userId * @param firstName * @param lastName * @param regId * @throws Exception */ public void sendRequestAuthorMailFromApp(String toEmail, String userId, String firstName, String lastName, String regId) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Author Request"); email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Registration Id: " + regId); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * @param toEmail// w w w .ja va2 s . com * @param userId * @param firstName * @param lastName * @param eventId * @param details * @throws Exception */ public void sendRequestMailForCalendarEventFromApp(String toEmail, String userId, String firstName, String lastName, String eventId, String details) throws Exception { Email email = new SimpleEmail(); email.setSmtpPort(Integer.parseInt(smtpPort)); email.setAuthenticator(new DefaultAuthenticator(fromAddress, fromPwd)); email.setDebug(Boolean.parseBoolean(debugEnabled)); email.setHostName(smtpSever); email.setFrom(fromAddress); email.setSubject("Calendar Event Request"); email.setMsg("User Id: " + userId + " Name: " + firstName + " " + lastName + " Event Id: " + eventId + "\n" + details); email.addTo(toEmail); email.setTLS(Boolean.parseBoolean(tlsEnabled)); email.setSocketTimeout(10000); email.setSocketConnectionTimeout(12000); email.send(); }
From source file:net.scran24.user.server.services.HelpServiceImpl.java
private void sendEmailNotification(String name, String surveyId, String number, List<String> addresses) { Email email = new SimpleEmail(); email.setHostName(smtpHostName); email.setSmtpPort(smtpPort);//from www .ja v a2 s .c o m email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword)); email.setSSLOnConnect(true); email.setCharset(EmailConstants.UTF_8); try { email.setFrom(fromEmail, fromName); email.setSubject("Someone needs help completing their survey"); email.setMsg("Please call " + name + " on " + number + " (survey id: " + surveyId + ")"); for (String address : addresses) email.addTo(address); email.send(); } catch (EmailException e) { log.error("Failed to send e-mail notification", e); } }
From source file:iddb.core.util.MailManager.java
private void setEmailProps(Email email) throws EmailException { email.setFrom(props.getProperty("from"), "IPDB"); if (props.containsKey("bounce")) email.setBounceAddress(props.getProperty("bounce")); if (props.containsKey("host")) email.setHostName(props.getProperty("host")); if (props.containsKey("port")) email.setSmtpPort(Integer.parseInt(props.getProperty("port"))); if (props.containsKey("username")) email.setAuthenticator(//ww w . j av a 2 s. c o m new DefaultAuthenticator(props.getProperty("username"), props.getProperty("password"))); if (props.containsKey("ssl") && props.getProperty("ssl").equalsIgnoreCase("true")) email.setSSL(true); if (props.containsKey("tls") && props.getProperty("tls").equalsIgnoreCase("true")) email.setTLS(true); if (props.containsKey("debug") && props.getProperty("debug").equalsIgnoreCase("true")) email.setDebug(true); }
From source file:json.JsonUI.java
public void enviandoEmail() { Properties login = new Properties(); String properties = "json/login.properties"; try {/* w w w . j a v a 2 s .c om*/ InputStream stream = ClassLoader.getSystemClassLoader().getResourceAsStream(properties); login.load(stream); } catch (IOException ex) { System.out.println("Erro: " + ex.getMessage()); } String username = login.getProperty("hotmail.username"); String password = login.getProperty("hotmail.password"); try { Email email = new SimpleEmail(); email.setHostName("smtp.live.com"); email.setSmtpPort(587); email.setStartTLSRequired(true); email.setAuthenticator(new DefaultAuthenticator(username, password)); email.setFrom(username); email.setSubject(assuntoEmail.getText()); email.setMsg(jTextAreaMsgEmail.getText()); email.addTo(emailDestino.getText()); email.setDebug(true); email.send(); aviso.setText("Mensagem enviada."); } catch (EmailException ex) { System.out.println("Erro: " + ex.getMessage()); } }