Example usage for org.apache.commons.mail Email setDebug

List of usage examples for org.apache.commons.mail Email setDebug

Introduction

In this page you can find the example usage for org.apache.commons.mail Email setDebug.

Prototype

public void setDebug(final boolean d) 

Source Link

Document

Setting to true will enable the display of debug information.

Usage

From source file:com.googlecode.fascinator.messaging.EmailNotificationConsumer.java

private void sendEmails(List<String> toList, List<String> ccList, String subject, String body,
        String fromAddress, String fromName, boolean isHtml) throws EmailException {
    Email email = null;
    if (isHtml) {
        email = new HtmlEmail();
        ((HtmlEmail) email).setHtmlMsg(body);
    } else {/*from   w ww. ja  va2  s  .  c o m*/
        email = new SimpleEmail();
        email.setMsg(body);
    }
    email.setDebug(debug);
    email.setHostName(smtpHost);
    if (smtpUsername != null || smtpPassword != null) {
        email.setAuthentication(smtpUsername, smtpPassword);
    }
    email.setSmtpPort(smtpPort);
    email.setSslSmtpPort(smtpSslPort);
    email.setSSL(smtpSsl);
    email.setTLS(smtpTls);
    email.setSubject(subject);

    for (String to : toList) {
        email.addTo(to);
    }
    if (ccList != null) {
        for (String cc : ccList) {
            email.addCc(cc);
        }
    }
    email.setFrom(fromAddress, fromName);
    email.send();
}

From source file:com.gst.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  ww  w  .j a v a2s .c  o  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("Welcome ")
                .append(emailDetail.getContactName()).append(" to ").append(emailDetail.getOrganisationName());

        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 Mifos.\n")
                .append("You can login using the following credentials:\nusername: ")
                .append(emailDetail.getUsername()).append("\n").append("password: ").append(unencodedPassword)
                .append("\n")
                .append("You must change this password upon first log in using Uppercase, Lowercase, number and character.\n")
                .append("Thank you and welcome to the organisation.");

        email.setMsg(messageBuilder.toString());

        email.addTo(sendToEmail, emailDetail.getContactName());
        email.send();
    } catch (final EmailException e) {
        throw new PlatformEmailSendException(e);
    }
}

From source file:au.edu.ausstage.utils.EmailManager.java

/**
 * A method for sending a simple email message
 *
 * @param subject the subject of the message
 * @param message the text of the message
 *
 * @return true, if and only if, the email is successfully sent
 *///from  w  ww .ja v  a2  s.c o  m
public boolean sendSimpleMessage(String subject, String message) {

    // check the input parameters
    if (InputUtils.isValid(subject) == false || InputUtils.isValid(message) == false) {
        throw new IllegalArgumentException("The subject and message parameters cannot be null");
    }

    try {
        // define helper variables
        Email email = new SimpleEmail();

        // configure the instance of the email class
        email.setSmtpPort(options.getPortAsInt());

        // define authentication if required
        if (InputUtils.isValid(options.getUser()) == true) {
            email.setAuthenticator(new DefaultAuthenticator(options.getUser(), options.getPassword()));
        }

        // turn on / off debugging
        email.setDebug(DEBUG);

        // set the host name
        email.setHostName(options.getHost());

        // set the from email address
        email.setFrom(options.getFromAddress());

        // set the subject
        email.setSubject(subject);

        // set the message
        email.setMsg(message);

        // set the to address
        String[] addresses = options.getToAddress().split(":");

        for (int i = 0; i < addresses.length; i++) {
            email.addTo(addresses[i]);
        }

        // set the security options
        if (options.getTLS() == true) {
            email.setTLS(true);
        }

        if (options.getSSL() == true) {
            email.setSSL(true);
        }

        // send the email
        email.send();

    } catch (EmailException ex) {
        if (DEBUG) {
            System.err.println("ERROR: Sending of email failed.\n" + ex.toString());
        }

        return false;
    }
    return true;
}

From source file:io.mapzone.controller.email.EmailService.java

public void send(Email email) throws EmailException {
    String env = System.getProperty("io.mapzone.controller.SMTP");
    if (env == null) {
        throw new IllegalStateException(
                "Environment variable missing: io.mapzone.controller.SMTPP. Format: <host>|<login>|<passwd>|<from>");
    }/*from   w w w .  j ava 2s  .  com*/
    String[] parts = StringUtils.split(env, "|");
    if (parts.length < 3 || parts.length > 4) {
        throw new IllegalStateException(
                "Environment variable wrong: io.mapzone.controller.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:json.JsonUI.java

public void enviandoEmail() {
    Properties login = new Properties();
    String properties = "json/login.properties";
    try {//from   w ww .ja v  a 2s. c om
        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:com.patrolpro.beans.SignupClientBean.java

public String sendEmail() {
    try {/*ww w .j  av  a2 s .c o m*/
        boolean isValid = validateInformation();

        if (isValid) {
            StringBuilder emailMessage = new StringBuilder();
            emailMessage.append("Contact Name: " + this.contactName + "\r\n");
            emailMessage.append("Contact Email: " + this.contactEmail + "\r\n");
            emailMessage.append("Contact Phone: " + this.contactPhone + "\r\n");
            emailMessage.append("Company Name: " + this.companyName + "\r\n");
            emailMessage.append(message);

            Email htmlEmail = new SimpleEmail();
            if (message == null || message.length() == 0) {
                message = "No message was provided by the user.";
            }
            htmlEmail.setFrom("signup@patrolpro.com");
            htmlEmail.setSubject("Trial Account Email!");
            htmlEmail.addTo("rharris@ainteractivesolution.com");
            htmlEmail.addTo("ijuneau@ainteractivesolution.com");
            htmlEmail.addCc("jc@champ.net");
            //htmlEmail.setHtmlMsg(emailMessage.toString());
            htmlEmail.setMsg(emailMessage.toString());
            //htmlEmail.setTextMsg(emailMessage.toString());

            htmlEmail.setDebug(true);
            htmlEmail.setAuthenticator(new MailAuthenticator("schedfox", "Sch3dF0x4m3"));
            htmlEmail.setHostName("mail2.champ.net");
            htmlEmail.setSmtpPort(587);
            htmlEmail.send();
            return "sentEmail";
        }
    } catch (Exception exe) {

    }
    return "invalid";
}

From source file:iddb.core.util.MailManager.java

private void setEmailProps(Email email) throws EmailException {
    email.setFrom(props.getProperty("from"), "IPDB");
    if (props.containsKey("bounce"))
        email.setBounceAddress(props.getProperty("bounce"));
    if (props.containsKey("host"))
        email.setHostName(props.getProperty("host"));
    if (props.containsKey("port"))
        email.setSmtpPort(Integer.parseInt(props.getProperty("port")));
    if (props.containsKey("username"))
        email.setAuthenticator(//from   ww w.  j  a  va  2  s  .c o m
                new DefaultAuthenticator(props.getProperty("username"), props.getProperty("password")));
    if (props.containsKey("ssl") && props.getProperty("ssl").equalsIgnoreCase("true"))
        email.setSSL(true);
    if (props.containsKey("tls") && props.getProperty("tls").equalsIgnoreCase("true"))
        email.setTLS(true);
    if (props.containsKey("debug") && props.getProperty("debug").equalsIgnoreCase("true"))
        email.setDebug(true);
}

From source file:com.mirth.connect.server.controllers.DefaultConfigurationController.java

@Override
public ConnectionTestResponse sendTestEmail(Properties properties) throws Exception {
    String portString = properties.getProperty("port");
    String encryption = properties.getProperty("encryption");
    String host = properties.getProperty("host");
    String timeoutString = properties.getProperty("timeout");
    Boolean authentication = Boolean.parseBoolean(properties.getProperty("authentication"));
    String username = properties.getProperty("username");
    String password = properties.getProperty("password");
    String to = properties.getProperty("toAddress");
    String from = properties.getProperty("fromAddress");

    int port = -1;
    try {//from  www  .  j a va2s.  c o m
        port = Integer.parseInt(portString);
    } catch (NumberFormatException e) {
        return new ConnectionTestResponse(ConnectionTestResponse.Type.FAILURE,
                "Invalid port: \"" + portString + "\"");
    }

    Email email = new SimpleEmail();
    email.setDebug(true);
    email.setHostName(host);
    email.setSmtpPort(port);

    try {
        int timeout = Integer.parseInt(timeoutString);
        email.setSocketTimeout(timeout);
        email.setSocketConnectionTimeout(timeout);
    } catch (NumberFormatException e) {
        // Don't set if the value is invalid
    }

    if ("SSL".equalsIgnoreCase(encryption)) {
        email.setSSLOnConnect(true);
        email.setSslSmtpPort(portString);
    } else if ("TLS".equalsIgnoreCase(encryption)) {
        email.setStartTLSEnabled(true);
    }

    if (authentication) {
        email.setAuthentication(username, password);
    }

    // These have to be set after the authenticator, so that a new mail session isn't created
    ConfigurationController configurationController = ControllerFactory.getFactory()
            .createConfigurationController();
    String protocols = properties.getProperty("protocols", StringUtils.join(
            MirthSSLUtil.getEnabledHttpsProtocols(configurationController.getHttpsClientProtocols()), ' '));
    String cipherSuites = properties.getProperty("cipherSuites", StringUtils.join(
            MirthSSLUtil.getEnabledHttpsCipherSuites(configurationController.getHttpsCipherSuites()), ' '));
    email.getMailSession().getProperties().setProperty("mail.smtp.ssl.protocols", protocols);
    email.getMailSession().getProperties().setProperty("mail.smtp.ssl.ciphersuites", cipherSuites);

    SSLSocketFactory socketFactory = (SSLSocketFactory) properties.get("socketFactory");
    if (socketFactory != null) {
        email.getMailSession().getProperties().put("mail.smtp.ssl.socketFactory", socketFactory);
        if ("SSL".equalsIgnoreCase(encryption)) {
            email.getMailSession().getProperties().put("mail.smtp.socketFactory", socketFactory);
        }
    }

    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());
    }
}

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 .java2 s .  c  o 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.apache.wookie.helpers.WidgetKeyManager.java

/**
 * Send email./*from   w w  w .j  av  a 2s . c  o m*/
 * 
 * @param mailserver - the SMTP mail server address
 * @param from
 * @param to
 * @param message
 * @throws Exception
 */
private static void sendEmail(String mailserver, int port, String from, String to, String message,
        String username, String password) throws EmailException {
    Email email = new SimpleEmail();
    email.setDebug(false); // true if you want to debug
    email.setHostName(mailserver);
    if (username != null) {
        email.setAuthentication(username, password);
        email.getMailSession().getProperties().put("mail.smtp.starttls.enable", "true");
    }
    email.setFrom(from, "Wookie Server");
    email.setSubject("Wookie API Key");
    email.setMsg(message);
    email.addTo(to);
    email.send();
}