List of usage examples for org.apache.commons.mail Email setFrom
public Email setFrom(final String email) throws EmailException
From source file:com.esofthead.mycollab.servlet.EmailValidationServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String smtpUserName = request.getParameter("smtpUserName"); String smtpPassword = request.getParameter("smtpPassword"); String smtpHost = request.getParameter("smtpHost"); String smtpPort = request.getParameter("smtpPort"); String tls = request.getParameter("tls"); int mailServerPort; try {// w w w . ja v a2 s . co m mailServerPort = Integer.parseInt(smtpPort); } catch (Exception e) { PrintWriter out = response.getWriter(); out.write("Port must be an integer value"); return; } try { Email email = new SimpleEmail(); email.setHostName(smtpHost); email.setSmtpPort(mailServerPort); email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword)); if (tls.equals("true")) { email.setSSLOnConnect(true); } else { email.setSSLOnConnect(false); } email.setFrom(smtpUserName); email.setSubject("MyCollab Test Email"); email.setMsg("This is a test mail ... :-)"); email.addTo(smtpUserName); email.send(); } catch (EmailException e) { PrintWriter out = response.getWriter(); out.write("Cannot establish SMTP connection. Please recheck your config."); return; } }
From source file:com.swissbit.ifttt.IFTTTConfgurationImpl.java
/** {@inheritDoc} */ @Override// w w w. j a va 2 s.co m public void trigger() { LOGGER.debug("IFTTT Email is getting sent..."); final List<String> tags = this.retrieveHashtags(this.m_hashTags); if (tags.size() == 0) { return; } if (tags.size() > 0) { for (final String tag : tags) { try { final Email email = new SimpleEmail(); email.setHostName(this.m_smtpHost); email.setSmtpPort(this.m_smtpPort); email.setAuthenticator(new DefaultAuthenticator(this.m_smtpUsername, this.m_smtpPassword)); email.setSSL(true); email.setFrom(this.m_smtpUsername); email.setSubject(tag); email.setMsg("This is a test mail ... :-)"); email.addTo(TRIGGER_EMAIL); email.send(); } catch (final EmailException e) { LOGGER.error(Throwables.getStackTraceAsString(e)); } } } LOGGER.debug("IFTTT Email is sent...Done"); }
From source file:ch.sdi.core.impl.mail.MailSenderDefault.java
/** * @see ch.sdi.core.intf.MailSender#sendMail(java.lang.Object) *//* www .j ava2 s. c o m*/ @Override public void sendMail(Email aMail) throws SdiException { aMail.setHostName(myHost); if (mySslOnConnect) { aMail.setSslSmtpPort("" + myPort); } else { aMail.setSmtpPort(myPort); } // if..else mySslOnConnect aMail.setAuthenticator(myAuthenticator); aMail.setSSLOnConnect(mySslOnConnect); aMail.setStartTLSRequired(myStartTlsRequired); try { aMail.setFrom(mySenderAddress); } catch (EmailException t) { throw new SdiException("Problems setting the sender address to mail: " + mySenderAddress, t, SdiException.EXIT_CODE_MAIL_ERROR); } if (myDryRun) { myLog.debug("DryRun is set. Not sending the mail"); // TODO: save locally in output dir } else { try { aMail.send(); myLog.debug("mail successfully sent"); } catch (Throwable t) { throw new SdiException("Problems sending a mail", t, SdiException.EXIT_CODE_MAIL_ERROR); } } // if..else myDryRun }
From source file:json.JsonUI.java
public void enviandoEmail() { Properties login = new Properties(); String properties = "json/login.properties"; try {/*from w w w . j a v a 2s . c o m*/ 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:cl.alma.scrw.bpmn.tasks.MailActivityBehavior.java
protected void setFrom(Email email, String from) { String fromAddres = null;/*from w w w .ja va2s. c om*/ if (from != null) { fromAddres = from; } else { // use default configured from address in process engine config fromAddres = Context.getProcessEngineConfiguration().getMailServerDefaultFrom(); } try { email.setFrom(fromAddres); } catch (EmailException e) { throw new ActivitiException("Could not set " + from + " as from address in email", e); } }
From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java
private int setBaseInfo(EmailInfo emailInfo, Email email) { try {//from w w w. ja v a 2s . co m //email.setDebug(true); email.setHostName(emailInfo.getHostName()); email.setSmtpPort(emailInfo.getPort()); email.setAuthentication(emailInfo.getUserName(), emailInfo.getPassword()); email.setCharset("UTF-8"); email.setSSLOnConnect(emailInfo.isSsl()); if (emailInfo.isSsl()) email.setSslSmtpPort(String.valueOf(emailInfo.getSslPort())); email.setFrom(emailInfo.getFrom()); } catch (EmailException e) { e.printStackTrace(); return -1; } return 0; }
From source file:edu.br.tcc.ManagedBean.TrabalhosBean.java
public Formulario enviarEmail(Formulario trabalho) { System.out.println("entrou no metodo do mb enviarEmail"); try {/* www. j a v a 2 s. c o 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:in.flipbrain.controllers.BaseController.java
protected void sendEmail(String to, String subject, String body) throws EmailException { logger.debug("Sending email to " + to + "\nSubject: " + subject + "\nMessage: " + body); if ("true".equalsIgnoreCase(getConfigValue(Constants.EM_FAKE_SEND))) return;/*from w w w . j av a2 s . c om*/ Email email = new SimpleEmail(); email.setHostName(getConfigValue("smtp.host")); email.setSmtpPort(Integer.parseUnsignedInt(getConfigValue("smtp.port"))); email.setAuthenticator( new DefaultAuthenticator(getConfigValue("smtp.user"), getConfigValue("smtp.password"))); email.setSSLOnConnect(Boolean.parseBoolean(getConfigValue("smtp.ssl"))); email.setFrom(getConfigValue("smtp.sender")); email.setSubject(subject); email.setMsg(body); email.addTo(to); email.send(); }
From source file:de.eod.jliki.users.jsfbeans.UserRegisterBean.java
/** * Adds a new user to the jLiki database.<br/> *//*from w w w . j av a2 s .com*/ 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:com.pkrete.locationservice.endpoint.mailer.impl.EmailServiceImpl.java
/** * Sends the given EmailMessage to the recipients defined in the message. * Returns true if and only if the message was successfully sent to all the * recipients; otherwise false./* w w w. jav a 2 s. c om*/ * * @param message email message to be sent * @return true if and only if the message was successfully sent to all the * recipients; otherwise false */ @Override public boolean send(EmailMessage message) { if (message == null) { logger.warn("Message cannot be null."); return false; } logger.debug("Create new \"{}\" email message.", message.getType().toString()); if (message.getRecipients().isEmpty()) { logger.info("No recipients defined. Nothing to do -> exit."); return false; } Email email = new SimpleEmail(); email.setHostName(PropertiesUtil.getProperty("mail.host")); email.setSmtpPort(this.converterService.strToInt(PropertiesUtil.getProperty("mail.port"))); email.setAuthenticator(new DefaultAuthenticator(PropertiesUtil.getProperty("mail.user"), PropertiesUtil.getProperty("mail.password"))); email.setTLS(true); try { // Set from address email.setFrom(message.getFrom()); // Set subject email.setSubject(message.getSubject()); // Build message body StringBuilder body = new StringBuilder(); if (!message.getHeader().isEmpty()) { body.append(message.getHeader()).append("\n\n"); } if (!message.getMessage().isEmpty()) { body.append(message.getMessage()).append("\n\n"); } if (!message.getFooter().isEmpty()) { body.append(message.getFooter()).append("\n\n"); } if (!message.getSignature().isEmpty()) { body.append(message.getSignature()).append("\n\n"); } // Set message contents email.setMsg(body.toString()); // Add message receivers for (String recipient : message.getRecipients()) { logger.info("Add recipient \"{}\".", recipient); email.addTo(recipient); } // Send message email.send(); logger.info("Email was succesfully sent to {} recipients.", message.getRecipients().size()); } catch (Exception e) { logger.error("Failed to send \"{}\" email message.", message.getType().toString()); logger.error(e.getMessage()); return false; } return true; }