List of usage examples for org.apache.commons.mail Email setAuthenticator
public void setAuthenticator(final Authenticator newAuthenticator)
Authenticator
to be used when authentication is requested from the mail server. From source file:easycar.controller.BookingListController.java
public void emailRemindAll() { FullBookingDto currentFullBookingDto; for (int i = 0; i < baseFullBookingList.size(); i++) { currentFullBookingDto = baseFullBookingList.get(i); if (!currentFullBookingDto.isRemindButtonOn()) { continue; }//from www. j av a 2s . c om Email email = new SimpleEmail(); email.setHostName("smtp.googlemail.com"); email.setSmtpPort(465); email.setAuthenticator(new DefaultAuthenticator("easycarremind", "easycartest")); email.setSSLOnConnect(true); try { email.setFrom("easycarremind@gmail.com"); email.setSubject("Reminder to return car"); email.setMsg("Dear " + currentFullBookingDto.getCustomerName() + ",\n\nPlease note that you are supposed to return the car with id " + currentFullBookingDto.getCarId() + " to us on " + currentFullBookingDto.getEndDateToDisplay() + "\n\nBest regards,\nEasy Car Team."); email.addTo(currentFullBookingDto.getCustomerEmail()); email.send(); } catch (EmailException e) { e.printStackTrace(); } currentFullBookingDto.setLastEmailRemindDate(getZeroTimeDate(new Date())); try { bookingService.editBooking(currentFullBookingDto); } catch (IOException e) { e.printStackTrace(); } } FacesContext.getCurrentInstance().addMessage("messageEmailRemindAll", new FacesMessage( FacesMessage.SEVERITY_INFO, dictionaryController.getDictionary().get("REMINDER_SENT"), null)); }
From source file:net.wikiadmin.clientnotification.SendMain.java
/** sendMainText. */ void sendMainText(String cMail, String cName, String cCredit) { /* i need your data!!! :D */ XmlProp readData = new XmlProp("mailsettings.xml"); readData.readData();/*from w ww. ja v a 2 s .c o m*/ userS = readData.getUser(); passS = readData.getpass(); hostS = readData.gethost(); portS = readData.getport(); sslS = readData.getssl(); fromS = readData.getfrom(); toS = cMail; intPortS = Integer.parseInt(portS); sslBoolean = Boolean.parseBoolean(sslS); themeText = readData.getTheme(); bodyText = readData.getBody() + cName + ".\n" + readData.getBodyP2() + cCredit + readData.getBodyP3() + "\n" + readData.getBodyContacts(); try { Email email = new SimpleEmail(); email.setHostName(hostS); email.setAuthenticator(new DefaultAuthenticator(userS, passS)); email.setSSLOnConnect(sslBoolean); email.setSmtpPort(intPortS); email.setFrom(fromS); email.setSubject(themeText); email.setMsg(bodyText); email.addTo(toS); email.send(); } catch (EmailException ex) { ex.printStackTrace(); System.out.println(""); } }
From source file:org.apache.airavata.credential.store.notifier.impl.EmailNotifier.java
public void notifyMessage(NotificationMessage message) throws CredentialStoreException { try {//from w ww .ja v a 2 s .c o m Email email = new SimpleEmail(); email.setHostName(this.emailNotifierConfiguration.getEmailServer()); email.setSmtpPort(this.emailNotifierConfiguration.getEmailServerPort()); email.setAuthenticator(new DefaultAuthenticator(this.emailNotifierConfiguration.getEmailUserName(), this.emailNotifierConfiguration.getEmailPassword())); email.setSSLOnConnect(this.emailNotifierConfiguration.isSslConnect()); email.setFrom(this.emailNotifierConfiguration.getFromAddress()); EmailNotificationMessage emailMessage = (EmailNotificationMessage) message; email.setSubject(emailMessage.getSubject()); email.setMsg(emailMessage.getMessage()); email.addTo(emailMessage.getSenderEmail()); email.send(); } catch (EmailException e) { log.error("[CredentialStore]Error sending email notification message."); throw new CredentialStoreException("Error sending email notification message", e); } }
From source file:org.apache.fineract.infrastructure.core.service.GmailBackedPlatformEmailService.java
@Override public void sendToUserAccount(final EmailDetail emailDetail, final String unencodedPassword) { final Email email = new SimpleEmail(); final SMTPCredentialsData smtpCredentialsData = this.externalServicesReadPlatformService .getSMTPCredentials();/*from w w w .j a va 2 s .co m*/ final String authuserName = smtpCredentialsData.getUsername(); final String authuser = smtpCredentialsData.getUsername(); final String authpwd = smtpCredentialsData.getPassword(); // Very Important, Don't use email.setAuthentication() email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(false); // true if you want to debug email.setHostName(smtpCredentialsData.getHost()); try { if (smtpCredentialsData.isUseTLS()) { email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); } email.setFrom(authuser, authuserName); final StringBuilder subjectBuilder = new StringBuilder().append("Fineract Prototype Demo: ") .append(emailDetail.getContactName()).append(" user account creation."); email.setSubject(subjectBuilder.toString()); final String sendToEmail = emailDetail.getAddress(); final StringBuilder messageBuilder = new StringBuilder() .append("You are receiving this email as your email account: ").append(sendToEmail) .append(" has being used to create a user account for an organisation named [") .append(emailDetail.getOrganisationName()).append("] on Fineract Prototype Demo.") .append("You can login using the following credentials: username: ") .append(emailDetail.getUsername()).append(" password: ").append(unencodedPassword); email.setMsg(messageBuilder.toString()); email.addTo(sendToEmail, emailDetail.getContactName()); email.send(); } catch (final EmailException e) { throw new PlatformEmailSendException(e); } }
From source file:org.cobbzilla.mail.sender.SmtpMailSender.java
@Override public void send(SimpleEmailMessage message) throws EmailException { Email email = constructEmail(message); email.setHostName(config.getHost()); email.setSmtpPort(config.getPort()); if (config.getHasMailUser()) { email.setAuthenticator(new DefaultAuthenticator(config.getUser(), config.getPassword())); }//from ww w .j a va 2s .c o m email.setTLS(config.isTlsEnabled()); email.setSubject(message.getSubject()); if (message.getToName() != null) { email.addTo(message.getToEmail(), message.getToName()); } else { email.addTo(message.getToEmail()); } if (message.getBcc() != null) { email.addBcc(message.getBcc()); } if (message.getCc() != null) { email.addCc(message.getCc()); } if (message.getFromName() != null) { email.setFrom(message.getFromEmail(), message.getFromName()); } else { email.setFrom(message.getFromEmail()); } sendEmail_internal(email); }
From source file:org.dllearner.algorithms.qtl.experiments.PRConvergenceExperiment.java
private void sendFinishedMail() throws EmailException, IOException { Properties config = new Properties(); config.load(Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/dllearner/algorithms/qtl/qtl-mail.properties")); Email email = new SimpleEmail(); email.setHostName(config.getProperty("hostname")); email.setSmtpPort(465);/*from w w w . j a v a 2 s.co m*/ email.setAuthenticator( new DefaultAuthenticator(config.getProperty("username"), config.getProperty("password"))); email.setSSLOnConnect(true); email.setFrom(config.getProperty("from")); email.setSubject("QTL evaluation finished."); email.setMsg("QTL evaluation finished."); email.addTo(config.getProperty("to")); email.send(); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Create data information to compose the mail * * @param hostName//w w w . ja v a2 s .c om * @param smtpPort * @param from * @param username * @param password * @param email * @param ssl * @param tls * @param ignoreSslCertificateErrors */ private static void configureBasics(String hostName, Integer smtpPort, String from, String username, String password, Email email, Boolean ssl, Boolean tls, Boolean ignoreSslCertificateErrors) { if (hostName != null) { email.setHostName(hostName); } else { throw new IllegalArgumentException( "Missing settings in System Configuration (see Administration menu) - cannot send mail"); } if (StringUtils.isNotBlank(smtpPort + "")) { email.setSmtpPort(smtpPort); } else { throw new IllegalArgumentException( "Missing settings in System Configuration (see Administration menu) - cannot send mail"); } if (username != null) { email.setAuthenticator(new DefaultAuthenticator(username, password)); } email.setDebug(true); if (tls != null && tls) { email.setStartTLSEnabled(tls); email.setStartTLSRequired(tls); } if (ssl != null && ssl) { email.setSSLOnConnect(ssl); if (StringUtils.isNotBlank(smtpPort + "")) { email.setSslSmtpPort(smtpPort + ""); } } if (ignoreSslCertificateErrors != null && ignoreSslCertificateErrors) { try { Session mailSession = email.getMailSession(); Properties p = mailSession.getProperties(); p.setProperty("mail.smtp.ssl.trust", "*"); } catch (EmailException e) { // Ignore the exception. Can't be reached because the host name is always set above or an // IllegalArgumentException is thrown. } } if (StringUtils.isNotBlank(from)) { try { email.setFrom(from); } catch (EmailException e) { throw new IllegalArgumentException( "Invalid 'from' email setting in System Configuration (see Administration menu) - cannot send " + "mail", e); } } else { throw new IllegalArgumentException( "Missing settings in System Configuration (see Administration menu) - cannot send mail"); } }
From source file:org.graylog2.alerts.FormattedEmailAlertSender.java
private void sendEmail(String emailAddress, Stream stream, AlertCondition.CheckResult checkResult, List<Message> backlog) throws TransportConfigurationException, EmailException { LOG.debug("Sending mail to " + emailAddress); if (!configuration.isEnabled()) { throw new TransportConfigurationException( "Email transport is not enabled in server configuration file!"); }//from w w w .j av a 2 s . com final Email email = new SimpleEmail(); email.setCharset(EmailConstants.UTF_8); if (isNullOrEmpty(configuration.getHostname())) { throw new TransportConfigurationException( "No hostname configured for email transport while trying to send alert email!"); } else { email.setHostName(configuration.getHostname()); } email.setSmtpPort(configuration.getPort()); if (configuration.isUseSsl()) { email.setSslSmtpPort(Integer.toString(configuration.getPort())); } if (configuration.isUseAuth()) { email.setAuthenticator(new DefaultAuthenticator(Strings.nullToEmpty(configuration.getUsername()), Strings.nullToEmpty(configuration.getPassword()))); } email.setSSLOnConnect(configuration.isUseSsl()); email.setStartTLSEnabled(configuration.isUseTls()); if (pluginConfig != null && !isNullOrEmpty(pluginConfig.getString("sender"))) { email.setFrom(pluginConfig.getString("sender")); } else { email.setFrom(configuration.getFromEmail()); } email.setSubject(buildSubject(stream, checkResult, backlog)); email.setMsg(buildBody(stream, checkResult, backlog)); email.addTo(emailAddress); email.send(); }
From source file:org.graylog2.alerts.StaticEmailAlertSender.java
private void sendEmail(String emailAddress, Stream stream, AlertCondition.CheckResult checkResult, List<Message> backlog) throws TransportConfigurationException, EmailException { LOG.debug("Sending mail to " + emailAddress); if (!configuration.isEnabled()) { throw new TransportConfigurationException( "Email transport is not enabled in server configuration file!"); }// w w w.ja v a 2s . c om final Email email = new SimpleEmail(); email.setCharset(EmailConstants.UTF_8); if (Strings.isNullOrEmpty(configuration.getHostname())) { throw new TransportConfigurationException( "No hostname configured for email transport while trying to send alert email!"); } else { email.setHostName(configuration.getHostname()); } email.setSmtpPort(configuration.getPort()); if (configuration.isUseSsl()) { email.setSslSmtpPort(Integer.toString(configuration.getPort())); } if (configuration.isUseAuth()) { email.setAuthenticator(new DefaultAuthenticator(Strings.nullToEmpty(configuration.getUsername()), Strings.nullToEmpty(configuration.getPassword()))); } email.setSSLOnConnect(configuration.isUseSsl()); email.setStartTLSEnabled(configuration.isUseTls()); if (pluginConfig != null && !Strings.isNullOrEmpty(pluginConfig.getString("sender"))) { email.setFrom(pluginConfig.getString("sender")); } else { email.setFrom(configuration.getFromEmail()); } email.setSubject(buildSubject(stream, checkResult, backlog)); email.setMsg(buildBody(stream, checkResult, backlog)); email.addTo(emailAddress); email.send(); }
From source file:org.kuali.mobility.email.service.EmailServiceImpl.java
@Override public boolean sendEmail(String body, String subject, String emailAddressTo, String emailAddressFrom) { boolean emailSent = false; if (emailAddressFrom == null || StringUtils.isEmpty(emailAddressFrom)) { emailAddressFrom = kmeProperties.getProperty("email.from"); if (emailAddressFrom == null) { return emailSent; }/*from w w w. j a va 2 s.c o m*/ } if (emailAddressTo == null || StringUtils.isEmpty(emailAddressTo)) { return emailSent; } if (subject == null || StringUtils.isEmpty(subject)) { return emailSent; } if (body == null || StringUtils.isEmpty(body)) { return emailSent; } try { Email email = new SimpleEmail(); email.setHostName(kmeProperties.getProperty("email.host")); email.setSmtpPort(Integer.parseInt(kmeProperties.getProperty("email.port"))); email.setAuthenticator(new DefaultAuthenticator(kmeProperties.getProperty("email.username"), kmeProperties.getProperty("email.passsword"))); email.setSSLOnConnect(true); email.setFrom(emailAddressFrom); email.setSubject(subject); email.setMsg(body); email.addTo(emailAddressTo); email.send(); emailSent = true; LOG.debug("Mail Sent..."); } catch (EmailException e) { LOG.error("Mail send failed...", e); } return emailSent; }