List of usage examples for org.apache.commons.mail Email setSmtpPort
public void setSmtpPort(final int aPortNumber)
From source file:com.cws.esolutions.security.quartz.PasswordExpirationNotifier.java
/** * @see org.quartz.Job#execute(org.quartz.JobExecutionContext) */// w w w . j a v a 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:au.edu.ausstage.utils.EmailManager.java
/** * A method for sending a simple email message * * @param subject the subject of the message * @param message the text of the message * * @return true, if and only if, the email is successfully sent *//*from w w w . ja v a2s . com*/ public boolean sendSimpleMessage(String subject, String message) { // check the input parameters if (InputUtils.isValid(subject) == false || InputUtils.isValid(message) == false) { throw new IllegalArgumentException("The subject and message parameters cannot be null"); } try { // define helper variables Email email = new SimpleEmail(); // configure the instance of the email class email.setSmtpPort(options.getPortAsInt()); // define authentication if required if (InputUtils.isValid(options.getUser()) == true) { email.setAuthenticator(new DefaultAuthenticator(options.getUser(), options.getPassword())); } // turn on / off debugging email.setDebug(DEBUG); // set the host name email.setHostName(options.getHost()); // set the from email address email.setFrom(options.getFromAddress()); // set the subject email.setSubject(subject); // set the message email.setMsg(message); // set the to address String[] addresses = options.getToAddress().split(":"); for (int i = 0; i < addresses.length; i++) { email.addTo(addresses[i]); } // set the security options if (options.getTLS() == true) { email.setTLS(true); } if (options.getSSL() == true) { email.setSSL(true); } // send the email email.send(); } catch (EmailException ex) { if (DEBUG) { System.err.println("ERROR: Sending of email failed.\n" + ex.toString()); } return false; } return true; }
From source file:com.northernwall.hadrian.workItem.email.EmailWorkItemSender.java
private void emailWorkItem(String subject, String body) { try {//from www.ja v a2 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:edu.br.tcc.ManagedBean.TrabalhosBean.java
public Formulario enviarEmail(Formulario trabalho) { System.out.println("entrou no metodo do mb enviarEmail"); try {//from w ww . ja va 2 s .co m 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: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);/*from w w w . j a v a 2 s . c o m*/ email.setSmtpPort(smtpPort); 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:json.JsonUI.java
public void enviandoEmail() { Properties login = new Properties(); String properties = "json/login.properties"; try {/* ww w .j ava2 s . com*/ 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()); } }
From source file:com.waveerp.sendMail.java
public void sendMsg(String strSource, String strSourceDesc, String strSubject, String strMsg, String strDestination, String strDestDesc) throws Exception { // Call the registry management system registrySystem rs = new registrySystem(); // Call the encryption management system desEncryption de = new desEncryption(); de.Encrypter("", ""); String strHost = rs.readRegistry("NA", "NA", "NA", "EMAILHOST"); String strPort = rs.readRegistry("NA", "NA", "NA", "EMAILPORT"); String strUser = rs.readRegistry("NA", "NA", "NA", "EMAILUSER"); String strPass = rs.readRegistry("NA", "NA", "NA", "EMAILPASSWORD"); log(DEBUG, strHost + "|" + strPort + "|" + strUser + "|" + strPass); //Decrypt the encrypted password. strPass = de.decrypt(strPass);//from w w w . j a v a 2 s.c o m Email email = new SimpleEmail(); email.setHostName(strHost); email.setSmtpPort(Integer.parseInt(strPort)); email.setAuthenticator(new DefaultAuthenticator(strUser, strPass)); email.setTLS(false); email.setFrom(strSource, strSourceDesc); email.setSubject(strSubject); email.setMsg(strMsg); email.addTo(strDestination, strDestDesc); email.send(); }
From source file:de.eod.jliki.users.jsfbeans.UserRegisterBean.java
/** * Adds a new user to the jLiki database.<br/> *//* www.j a v a 2 s . c o m*/ public final void addNewUser() { final User newUser = new User(this.username, this.password, this.email, this.firstname, this.lastname); final String userHash = UserDBHelper.addUserToDB(newUser); if (userHash == null) { Messages.addFacesMessage(null, FacesMessage.SEVERITY_ERROR, "message.user.register.failed", this.username); return; } UserRegisterBean.LOGGER.debug("Adding user: " + newUser.toString()); final FacesContext fc = FacesContext.getCurrentInstance(); final HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); final ResourceBundle mails = ResourceBundle.getBundle("de.eod.jliki.EMailMessages", fc.getViewRoot().getLocale()); final String activateEMailTemplate = mails.getString("user.registration.email"); final StringBuffer url = request.getRequestURL(); final String serverUrl = url.substring(0, url.lastIndexOf("/")); UserRegisterBean.LOGGER.debug("Generated key for user: \"" + userHash + "\""); final String emsLink = serverUrl + "/activate.xhtml?user=" + newUser.getName() + "&key=" + userHash; final String emsLikiName = ConfigManager.getInstance().getConfig().getPageConfig().getPageName(); final String emsEMailText = MessageFormat.format(activateEMailTemplate, emsLikiName, this.firstname, this.lastname, this.username, emsLink); final String emsHost = ConfigManager.getInstance().getConfig().getEmailConfig().getHostname(); final int emsPort = ConfigManager.getInstance().getConfig().getEmailConfig().getPort(); final String emsUser = ConfigManager.getInstance().getConfig().getEmailConfig().getUsername(); final String emsPass = ConfigManager.getInstance().getConfig().getEmailConfig().getPassword(); final boolean emsTSL = ConfigManager.getInstance().getConfig().getEmailConfig().isUseTLS(); final String emsSender = ConfigManager.getInstance().getConfig().getEmailConfig().getSenderAddress(); final Email activateEmail = new SimpleEmail(); activateEmail.setHostName(emsHost); activateEmail.setSmtpPort(emsPort); activateEmail.setAuthentication(emsUser, emsPass); activateEmail.setTLS(emsTSL); try { activateEmail.setFrom(emsSender); activateEmail.setSubject("Activate jLiki Account"); activateEmail.setMsg(emsEMailText); activateEmail.addTo(this.email); activateEmail.send(); } catch (final EmailException e) { UserRegisterBean.LOGGER.error("Sending activation eMail failed!", e); return; } this.username = ""; this.password = ""; this.confirm = ""; this.email = ""; this.firstname = ""; this.lastname = ""; this.captcha = ""; this.termsOfUse = false; this.success = true; Messages.addFacesMessage(null, FacesMessage.SEVERITY_INFO, "message.user.registered", this.username); }
From source file:edu.corgi.uco.sendEmails.java
public void sendConfirmation(String email2, String firstName, String lastName, int token, int id) throws EmailException { Email email = new SimpleEmail(); email.setDebug(true);// w ww .ja v a2 s . c o 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 Corgi"); email.setSubject("Account Confirmation"); email.setMsg(firstName + " " + lastName + " please go to the following address http://localhost:8080/Corgi/faces/accountAuth.xhtml " + "and enter the token:" + token + " and the ID:" + id + " to confirm and activate your account"); System.out.print("Email Address: " + email2); email.addTo(email2); email.send(); }
From source file:FacultyAdvisement.SignupBean.java
public String validateSignUp(ArrayList<Course> list, Appointment appointment) throws SQLException, IOException, EmailException { if (this.desiredCoureses == null || this.desiredCoureses.size() < 1) { FacesContext.getCurrentInstance().addMessage("desiredCourses:Submit", new FacesMessage(FacesMessage.SEVERITY_FATAL, "Please select some courses before confirming an appointment.", null)); }//from www . j ava 2 s. c o m for (int i = 0; i < list.size(); i++) { if (!this.checkRequsites(CourseRepository.readCourseWithRequisites(ds, list.get(i)))) { return null; } } try { DesiredCourseRepository.deleteFromAppointment(ds, this.appointment.aID); } catch (SQLException ex) { Logger.getLogger(UserBean.class.getName()).log(Level.SEVERE, null, ex); } DesiredCourseRepository.createDesiredCourses(ds, desiredCoureses, Long.toString(appointment.aID)); if (!this.edit) { try { 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 Appointmen Confirmation"); StringBuilder table = new StringBuilder(); table.append("<style>" + "td" + "{border-left:1px solid black;" + "border-top:1px solid black;}" + "table" + "{border-right:1px solid black;" + "border-bottom:1px solid black;}" + "</style>"); table.append( "<table><tr><td width=\"350\">Course Name</td><td width=\"350\">Course Subject</td><td width=\"350\">Course Number</td><td width=\"350\">Course Credits</td></tr> </table>"); for (int i = 0; i < this.desiredCoureses.size(); i++) { table.append("<tr><td width=\"350\">" + this.desiredCoureses.get(i).getName() + "</td>" + "<td width=\"350\">" + this.desiredCoureses.get(i).getSubject() + "</td>" + "<td width=\"350\">" + this.desiredCoureses.get(i).getNumber() + "</td>" + "<td width=\"350\">" + this.desiredCoureses.get(i).getCredits() + "</td></tr>" ); } email.setMsg("<p>Your appointment with your faculty advisor is at " + appointment.datetime + " on " + appointment.date + " . </p>" + "<p align=\"center\">Desired Courses</p>" + table.toString() + "<p align=\"center\">UCO Faculty Advisement</p></font>" ); email.addTo(username); email.send(); } catch (EmailException ex) { Logger.getLogger(VerificationBean.class.getName()).log(Level.SEVERE, null, ex); } } return "/customerFolder/profile.xhtml"; }