List of usage examples for org.apache.commons.mail Email setDebug
public void setDebug(final boolean d)
From source file:org.chenillekit.mail.services.impl.MailServiceImpl.java
private void setEmailStandardData(Email email) { email.setHostName(smtpServer);// w w w. j a v a 2 s. co m if (smtpUser != null && smtpUser.length() > 0) email.setAuthentication(smtpUser, smtpPassword); email.setDebug(smtpDebug); email.setSmtpPort(smtpPort); email.setSSL(smtpSSL); email.setSslSmtpPort(String.valueOf(smtpSslPort)); email.setTLS(smtpTLS); }
From source file:org.fao.geonet.util.MailUtil.java
/** * Create data information to compose the mail * * @param hostName/*from w w w . java 2 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.mifosplatform.billing.message.service.MessageGmailBackedPlatformEmailService.java
@Override public void sendToUserEmail() { Email email = new SimpleEmail(); String authuserName = "info@hugotechnologies.com"; //String authusername="hugotechnologies"; String authuser = "ashokcse556@gmail.com"; String authpwd = "9989720715"; // Very Important, Don't use email.setAuthentication() email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(true); // true if you want to debug email.setHostName("smtp.gmail.com"); try {//w w w . ja v a 2s .c om email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); email.setFrom(authuserName, authuser); List<BillingMessageDataForProcessing> billingMessageDataForProcessings = this.billingMesssageReadPlatformService .retrieveMessageDataForProcessing(); for (BillingMessageDataForProcessing emailDetail : billingMessageDataForProcessings) { StringBuilder subjectBuilder = new StringBuilder().append(" ").append(emailDetail.getSubject()) .append(" "); email.setSubject(subjectBuilder.toString()); String sendToEmail = emailDetail.getMessageTo(); StringBuilder messageBuilder = new StringBuilder().append(emailDetail.getHeader()).append(".") .append(emailDetail.getBody()).append(",").append(emailDetail.getFooter()); email.setMsg(messageBuilder.toString()); email.addTo(sendToEmail, emailDetail.getMessageFrom()); email.setSmtpPort(587); email.send(); BillingMessage billingMessage = this.messageDataRepository.findOne(emailDetail.getId()); if (billingMessage.getStatus().contentEquals("N")) { billingMessage.updateStatus(); } this.messageDataRepository.save(billingMessage); } } catch (EmailException e) { throw new MessagePlatformEmailSendException(e); } }
From source file:org.mifosplatform.infrastructure.core.service.GmailBackedPlatformEmailService.java
@Override public void sendToUserAccount(final EmailDetail emailDetail, final String unencodedPassword) { final Email email = new SimpleEmail(); final String authuserName = "support@cloudmicrofinance.com"; final String authuser = "support@cloudmicrofinance.com"; final String authpwd = "support80"; // Very Important, Don't use email.setAuthentication() email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(false); // true if you want to debug email.setHostName("smtp.gmail.com"); try {/*from www.j av a2 s .c om*/ email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); email.setFrom(authuser, authuserName); final StringBuilder subjectBuilder = new StringBuilder().append("MifosX 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 MifosX 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.mifosplatform.infrastructure.core.service.GmailPlatformEmailService.java
@Override public void sendToUserAccount(final EmailDetail emailDetail, final String unencodedPassword) { final Email email = new SimpleEmail(); // Very Important, Don't use email.setAuthentication() email.setAuthenticator(/*from w w w. j av a2 s . c o m*/ new DefaultAuthenticator(credentials.getAuthUsername(), credentials.getAuthPassword())); email.setDebug(false); // true if you want to debug email.setHostName("smtp.gmail.com"); email.setSmtpPort(credentials.getSmtpPort()); try { email.setStartTLSRequired(true); email.setStartTLSEnabled(credentials.isStartTls()); email.setFrom(credentials.getAuthUsername(), credentials.getAuthUsername()); final StringBuilder subjectBuilder = new StringBuilder().append("FINEM U Ltd.: ") .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("].") .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.mifosplatform.infrastructure.core.service.GmailSendingNotificationToClients.java
public void sendToUserAccount(final String mailAddress, final String approviedDate, final String type, final String money) { final Email email = new SimpleEmail(); final String authuserName = "raghuchiluka111@gmail.com"; final String authuser = "raghuchiluka111@gmail.com"; final String authpwd = "raghuAkhila"; // Very Important, Don't use email.setAuthentication() email.setAuthenticator(new DefaultAuthenticator(authuser, authpwd)); email.setDebug(false); // true if you want to debug email.setHostName("smtp.gmail.com"); email.setSmtpPort(587);//from ww w . ja v a2s . com try { email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true"); email.setFrom(authuser, authuserName); final StringBuilder subjectBuilder = new StringBuilder().append(type + ": "); email.setSubject(subjectBuilder.toString()); StringBuilder messageBuilder = null; if (money != null) messageBuilder = new StringBuilder().append(type + ": ").append(approviedDate) .append("Amount Disbursed:").append(money); else messageBuilder = new StringBuilder().append(type + ": ").append(approviedDate); email.setMsg(messageBuilder.toString()); email.addTo(mailAddress, mailAddress); email.send(); } catch (final EmailException e) { throw new PlatformEmailSendException(e); } }
From source file:org.mifosplatform.infrastructure.security.service.JpaPlatformUserLoginFailureService.java
private void notify(String username, Integer failures) { GlobalConfigurationProperty property = globalConfigurationRepository.findOneByName("login-failure-limit"); Long limit = 3l;/*w w w. j a v a 2 s. c o m*/ if (property != null && property.isEnabled() && property.getValue() != null) { limit = property.getValue(); } // NOTE: only send the email once if (failures == limit.intValue()) { lock(username); try { StringBuilder message = new StringBuilder(); message.append(String.format(template, limit)); final Email email = new SimpleEmail(); EmailCredentialsData credentials = getCredentials(); email.setAuthenticator( new DefaultAuthenticator(credentials.getAuthUsername(), credentials.getAuthPassword())); email.setDebug(credentials.isDebug()); email.setHostName(credentials.getHost()); email.setSmtpPort(credentials.getSmtpPort()); email.setStartTLSRequired(true); email.setStartTLSEnabled(credentials.isStartTls()); email.getMailSession().getProperties().put("mail.smtp.auth", true); email.setFrom(credentials.getAuthUsername(), credentials.getSenderName()); email.setSubject(subject); email.setMsg(message.toString()); email.addTo(appUserRepository.getEmailByUsername(username)); email.send(); } catch (Exception e) { logger.warn(e.toString(), e); } throw new LockedException( "User " + username + " has been locked after " + limit + " failed login attempts."); } }
From source file:org.polymap.rhei.um.email.EmailService.java
public void send(Email email) throws EmailException { String env = System.getProperty("org.polymap.rhei.um.SMTP"); if (env == null) { throw new IllegalStateException( "Environment variable missing: org.polymap.rhei.um.SMTP. Format: <host>|<login>|<passwd>|<from>"); }/*from w ww. jav a2 s.c om*/ String[] parts = StringUtils.split(env, "|"); if (parts.length < 3 || parts.length > 4) { throw new IllegalStateException( "Environment variable wrong: org.polymap.rhei.um.SMTP. Format: <host>|<login>|<passwd>|<from> : " + env); } email.setDebug(true); email.setHostName(parts[0]); //email.setSmtpPort( 465 ); //email.setSSLOnConnect( true ); email.setAuthenticator(new DefaultAuthenticator(parts[1], parts[2])); if (email.getFromAddress() == null && parts.length == 4) { email.setFrom(parts[3]); } if (email.getSubject() == null) { throw new EmailException("Missing subject."); } email.send(); }
From source file:org.xerela.server.birt.ReportJob.java
private void setupEmail(JobExecutionContext executionContext, String emailTo, String emailCc, Email email) throws AddressException, EmailException { InternetAddress[] toAddrs = InternetAddress.parse(emailTo); email.setTo(Arrays.asList(toAddrs)); if (emailCc != null && emailCc.trim().length() > 0) { InternetAddress[] ccAddrs = InternetAddress.parse(emailCc); email.setCc(Arrays.asList(ccAddrs)); }/* w w w . j a v a 2s .com*/ email.setCharset("utf-8"); //$NON-NLS-1$ email.setHostName(System.getProperty(MAIL_HOST_PROP, "mail")); //$NON-NLS-1$ String authUser = System.getProperty(MAIL_AUTH_USER_PROP); if (authUser != null) { email.setAuthentication(authUser, System.getProperty(MAIL_AUTH_PASSWORD_PROP)); } email.setFrom(System.getProperty(MAIL_FROM_PROP), System.getProperty(MAIL_FROM_NAME_PROP)); email.setSubject( Messages.bind(Messages.ReportJob_emailSubject, executionContext.getJobDetail().getFullName())); email.addHeader("X-Mailer", "Xerela Mailer"); //$NON-NLS-1$ //$NON-NLS-2$ email.setDebug(Boolean.getBoolean("org.xerela.mail.debug")); //$NON-NLS-1$ }