List of usage examples for org.apache.commons.mail Email setMsg
public abstract Email setMsg(String msg) throws EmailException;
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//from w w w . ja v a 2s. c o m * @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:net.sasasin.sreader.batch.publish.GMailPublisher.java
@Override public void publish(ContentViewId content) { try {// w ww .j av a 2s .c o m Email email = new SimpleEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(587); email.setStartTLSEnabled(true); email.setCharset("UTF-8"); email.setAuthenticator(new DefaultAuthenticator(content.getEmail(), content.getPassword())); email.setFrom(content.getEmail()); email.addTo(content.getEmail()); email.setSubject(content.getTitle()); email.setMsg(content.getUrl() + "\n" + content.getFullText()); email.send(); log(content); } catch (EmailException e) { e.printStackTrace(); } }
From source file:com.pronoiahealth.olhie.server.services.MailSendingService.java
/** * @param toEmail/* w w w. ja v a2 s .c o m*/ * @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:beanView.MbVListaEmail.java
public void sendMail() { String subject = nombre + " " + eMail; try {//from ww w .ja va 2 s .com Email email = new SimpleEmail(); email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("altabar.listas", "Nivde017")); email.setSSLOnConnect(true); email.isStartTLSEnabled(); email.setFrom("altabar.listas@gmail.com"); email.setSubject(subject); email.setMsg(message); email.addTo("eacunagon@gmail.com"); email.send(); FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Listo!", "Lista enviada")); } catch (Exception ex) { FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", ex.getMessage())); eMail = ""; nombre = ""; message = ""; } }
From source file:com.projetIF4.controller.MailControleur.java
public void mail() throws EmailException { Email email = new SimpleEmail(); email.setCharset("UTF-8"); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465);/* ww w . j a va 2s .c om*/ email.setAuthenticator(new DefaultAuthenticator("fst.rnu.info@gmail.com", "adminFST123456789")); email.setSSLOnConnect(true); email.setFrom("fst.rnu.info@gmail.com", "Dpartement Informatique FST"); email.setSubject(objet); email.setMsg(message); email.addTo(mailDestination); email.send(); }
From source file:gobblin.util.EmailUtils.java
/** * A general method for sending emails./* w w w .java 2 s . c o m*/ * * @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:ch.fihlon.moodini.business.token.control.TokenService.java
@SneakyThrows private void sendChallenge(@NotNull final String email, @NotNull final Challenge challenge) { final SmtpConfiguration smtp = configuration.getSmtp(); final Email mail = new SimpleEmail(); mail.setHostName(smtp.getHostname()); mail.setSmtpPort(smtp.getPort());/*from www . j a v a 2 s. co m*/ mail.setAuthenticator(new DefaultAuthenticator(smtp.getUser(), smtp.getPassword())); mail.setSSLOnConnect(smtp.getSsl()); mail.setFrom(smtp.getFrom()); mail.setSubject("Your challenge to login to Moodini"); mail.setMsg(String.format("Your one time challenge, valid for 10 minutes: %s", challenge.getChallenge())); mail.addTo(email); mail.send(); }
From source file:FacultyAdvisement.ImagineBean.java
public String submitRequest() { String emailCourses = ""; for (Course c : currentCourses) { emailCourses += "<li>" + c.getSubject() + " " + c.getNumber() + "</li>"; }/* w w w . java2 s . co m*/ 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("Microsoft Imagine Account"); email.setMsg("<font size=\"3\" style=\"font-family:verdana\"> \n" + "<ul><li>Student Name: " + student.getFirstName() + " " + student.getLastName() + "</li><li>Student Major: " + student.getMajorCode() + "<li>Current Courses: <ol>" + emailCourses + "</ol></li></ul> " + "Student Email if needed for response: " + student.getUsername() + "\n<p align=\"center\">UCO Faculty Advisement</p></font>"); email.addTo("uco.faculty.advisement@gmail.com"); email.send(); } catch (EmailException ex) { Logger.getLogger(VerificationBean.class.getName()).log(Level.SEVERE, null, ex); } return "/customerFolder/imagineConfirm"; }
From source file:br.com.verificanf.bo.NotaBO.java
public void buscar() { /*Inicio - Pegar Configuraes de email do arquivo*/ try {//from w w w . ja v a2 s .co m String local = new File("./email.txt").getCanonicalFile().toString(); File arq = new File(local); boolean existe = arq.exists(); if (existe) { FileReader fr = new FileReader(arq); BufferedReader br = new BufferedReader(fr); while (br.ready()) { String linha = br.readLine(); if (linha.contains("host:")) { hostEmail = linha.replace("host:", "").replace(" ", ""); } if (linha.contains("port:")) { portEmail = linha.replace("port:", "").replace(" ", ""); } if (linha.contains("user:")) { userEmail = linha.replace("user:", "").replace(" ", ""); } if (linha.contains("pass:")) { passEmail = linha.replace("pass:", "").replace(" ", ""); } if (linha.contains("from:")) { fromEmail = linha.replace("from:", "").replace(" ", ""); } if (linha.contains("to:")) { toEmail = linha.replace("to:", "").replace(" ", ""); } } } } catch (FileNotFoundException ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); StackTraceElement st[] = ex.getStackTrace(); String erro = ""; for (int i = 0; i < st.length; i++) { erro += st[i].toString() + "\n"; } } catch (IOException ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); StackTraceElement st[] = ex.getStackTrace(); String erro2 = ""; for (int i = 0; i < st.length; i++) { erro2 += st[i].toString() + "\n"; } } /*FIM - Pegar Configuraes de email do arquivo*/ NotaDAO notaDAO = new NotaDAO(); try { ultimasAtual = notaDAO.getUltimaNotaMesAtual(); ultimasAnterior = notaDAO.getUltimaNotaMesAnterior(); naoEncontradas = new ArrayList<>(); for (Nota notaAnterior : ultimasAnterior) { for (Nota notaAtual : ultimasAtual) { if (notaAnterior.getLoja() == notaAtual.getLoja()) { //System.out.println("Anterior Loja: "+notaAnterior.getLoja()+" Nota: "+notaAnterior.getNumero()); //System.out.println("Atual Loja: "+notaAtual.getLoja()+" Nota: "+notaAtual.getNumero()); Integer numero = 0; for (Integer i = notaAnterior.getNumero(); i <= notaAtual.getNumero(); i++) { numero = i; Nota notacorrente = new Nota(); notacorrente.setLoja(notaAnterior.getLoja()); notacorrente.setNumero(numero); notacorrente.setSerie(notaAnterior.getSerie()); //System.out.println("Corrente Loja: "+notacorrente.getLoja()+" Nota: "+notacorrente.getNumero()); if (!notaDAO.notaIsValida(notacorrente)) { System.out.println("Loja " + notaAnterior.getLoja() + " Numero: " + numero); naoEncontradas.add(notacorrente); msg = msg.concat(" Loja: " + notacorrente.getLoja() + " Nota: " + notacorrente.getNumero() + " Serie: " + notacorrente.getSerie() + " \n"); } } } } } if (naoEncontradas.size() > 0) { Email email = new SimpleEmail(); email.setHostName(hostEmail); email.setSmtpPort(Integer.parseInt(portEmail)); email.setAuthentication(userEmail, passEmail); email.setFrom(fromEmail); email.setSubject("Alerta Nerus!!"); email.setMsg(msg); email.addTo(toEmail); email.send(); } } catch (Exception ex) { Logger.getLogger(NotaBO.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.turn.sorcerer.util.email.Emailer.java
private void sendEmail() throws EmailException, UnknownHostException { List<String> addresses = Lists .newArrayList(Splitter.on(',').omitEmptyStrings().trimResults().split(ADMIN_EMAIL.getAdmins())); logger.info("Sending email to {}", addresses.toString()); Email email = new HtmlEmail(); email.setHostName(ADMIN_EMAIL.getHost()); email.setSocketTimeout(30000); // 30 seconds email.setSocketConnectionTimeout(30000); // 30 seconds for (String address : addresses) { email.addTo(address);//from ww w.j a v a 2 s.co m } email.setFrom( SorcererInjector.get().getModule().getName() + "@" + InetAddress.getLocalHost().getHostName()); email.setSubject(title); email.setMsg(body); email.send(); }