List of usage examples for org.apache.commons.mail Email setSmtpPort
public void setSmtpPort(final int aPortNumber)
From source file:com.pax.pay.trans.receipt.paperless.AReceiptEmail.java
private int setBaseInfo(EmailInfo emailInfo, Email email) { try {/*from ww w. j a v a 2 s . c o 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:com.mirth.connect.connectors.smtp.SmtpSenderService.java
@Override public Object invoke(String channelId, String method, Object object, String sessionId) throws Exception { if (method.equals("sendTestEmail")) { SmtpDispatcherProperties props = (SmtpDispatcherProperties) object; String host = replacer.replaceValues(props.getSmtpHost(), channelId); String portString = replacer.replaceValues(props.getSmtpPort(), channelId); int port = -1; try {//w w w.j a va 2 s . c om port = Integer.parseInt(portString); } catch (NumberFormatException e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, "Invalid port: \"" + portString + "\""); } String secure = props.getEncryption(); boolean authentication = props.isAuthentication(); String username = replacer.replaceValues(props.getUsername(), channelId); String password = replacer.replaceValues(props.getPassword(), channelId); String to = replacer.replaceValues(props.getTo(), channelId); String from = replacer.replaceValues(props.getFrom(), channelId); Email email = new SimpleEmail(); email.setDebug(true); email.setHostName(host); email.setSmtpPort(port); if ("SSL".equalsIgnoreCase(secure)) { email.setSSL(true); } else if ("TLS".equalsIgnoreCase(secure)) { email.setTLS(true); } if (authentication) { email.setAuthentication(username, password); } email.setSubject("Mirth Connect Test Email"); try { for (String toAddress : StringUtils.split(to, ",")) { email.addTo(toAddress); } email.setFrom(from); email.setMsg( "Receipt of this email confirms that mail originating from this Mirth Connect Server is capable of reaching its intended destination.\n\nSMTP Configuration:\n- Host: " + host + "\n- Port: " + port); email.send(); return new ConnectionTestResponse(ConnectionTestResponse.Type.SUCCESS, "Sucessfully sent test email to: " + to); } catch (EmailException e) { return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE, e.getMessage()); } } 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 a va 2s.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: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./* www . ja va2 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; }
From source file:Control.CommonsMail.java
/** * Classe que envia E-amil//from w w w . j ava 2 s.c o m * @throws EmailException */ public void enviaEmailSimples(String Msg) throws EmailException { Email email = new SimpleEmail(); email.setDebug(true); email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail //email.setHostName("smtp.pharmapele.com.br"); // o servidor SMTP para envio do e-mail email.setSmtpPort(587); email.setSSLOnConnect(true); email.setStartTLSEnabled(true); email.setAuthentication("softwaredeveloperantony@gmail.com", "tony#020567"); //email.setAuthentication("antony@pharmapele.com.br", "tony#020567"); //email.setFrom("softwaredeveloperantony@gmail.com"); // remetente email.setFrom("antony@pharmapele.com.br"); // remetente email.setSubject("Exporta Estoque lojas"); // assunto do e-mail email.setMsg(Msg); //conteudo do e-mail email.addTo("antony@pharmapele.com.br", "Antony"); //destinatrio //email.sets(true); //email.setTLS(true); try { email.send(); } catch (Exception e) { e.printStackTrace(); } }
From source file:br.com.verificanf.bo.NotaBO.java
public void buscar() { /*Inicio - Pegar Configuraes de email do arquivo*/ try {/* w ww . ja va 2 s . c om*/ 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.pkrete.locationservice.admin.mailer.impl.BasicEmailService.java
/** * Send an email to the given user when the user is created or the password * is modified.// w w w . j av a 2s. co m * * @param user the receiver of the email */ @Override public void send(UserFull user) { logger.info("Create new email message."); 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 { // Init variables String header = null; String msg = null; // Set from address email.setFrom(this.messageSource.getMessage("mail.from", null, null)); // Set message arguments Object[] args = new Object[] { user.getUsername(), user.getPasswordUi() }; // Set variables values if (user.getUpdated() == null) { // This is a new user if (logger.isDebugEnabled()) { logger.debug("The message is for a new user."); } // Set subject email.setSubject(this.messageSource.getMessage("mail.title.add", null, null)); // Set message header header = this.messageSource.getMessage("mail.header.add", null, null); // Set message content msg = this.messageSource.getMessage("mail.message.add", args, null); } else { // This is an existing user logger.debug("The message is for an existing user."); // Set subject email.setSubject(this.messageSource.getMessage("mail.title.edit", null, null)); // Get message header header = this.messageSource.getMessage("mail.header.edit", null, null); // Get message content msg = this.messageSource.getMessage("mail.message.edit", args, null); } // Get note String note = this.messageSource.getMessage("mail.note", null, null); // Get footer String footer = this.messageSource.getMessage("mail.footer", null, null); // Get signature String signature = this.messageSource.getMessage("mail.signature", null, null); // Build message body StringBuilder result = new StringBuilder(); if (!header.isEmpty()) { result.append(header).append("\n\n"); } if (!msg.isEmpty()) { result.append(msg).append("\n\n"); } if (!note.isEmpty()) { result.append(note).append("\n\n"); } if (!footer.isEmpty()) { result.append(footer).append("\n\n"); } if (!signature.isEmpty()) { result.append(signature).append("\n\n"); } // Set message contents email.setMsg(result.toString()); // Set message receiver email.addTo(user.getEmail()); // Send message email.send(); logger.info("Email was sent to \"{}\".", user.getEmail()); } catch (Exception e) { logger.error("Failed to send email to \"{}\".", user.getEmail()); logger.error(e.getMessage(), e); } }
From source file:ch.sdi.core.impl.mail.MailSenderDefault.java
/** * @see ch.sdi.core.intf.MailSender#sendMail(java.lang.Object) *//* w w w . j ava 2s . 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:fr.gael.dhus.messaging.mail.MailServer.java
public void send(Email email, String to, String cc, String bcc, String subject) throws EmailException { email.setHostName(getSmtpServer());/*from w ww .j a v a2 s.co m*/ email.setSmtpPort(getPort()); if (getUsername() != null) { email.setAuthentication(getUsername(), getPassword()); } if (getFromMail() != null) { if (getFromName() != null) email.setFrom(getFromMail(), getFromName()); else email.setFrom(getFromMail()); } if (getReplyto() != null) { try { email.setReplyTo(ImmutableList.of(new InternetAddress(getReplyto()))); } catch (AddressException e) { logger.error("Cannot configure Reply-to (" + getReplyto() + ") into the mail: " + e.getMessage()); } } // Message configuration email.setSubject("[" + cfgManager.getNameConfiguration().getShortName() + "] " + subject); email.addTo(to); // Add CCed if (cc != null) { email.addCc(cc); } // Add BCCed if (bcc != null) { email.addBcc(bcc); } email.setStartTLSEnabled(isTls()); try { email.send(); } catch (EmailException e) { logger.error("Cannot send email: " + e.getMessage()); throw e; } }
From source file:com.swissbit.ifttt.IFTTTConfgurationImpl.java
/** {@inheritDoc} */ @Override// ww w. j av a2 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"); }