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

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

Introduction

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

Prototype

public void setHostName(final String aHostName) 

Source Link

Document

Set the hostname of the outgoing mail server.

Usage

From source file:beanView.MbVListaEmail.java

public void sendMail() {
    String subject = nombre + " " + eMail;
    try {/*from  w ww  .j  av  a2 s  .  c  om*/

        Email email = new SimpleEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("altabar.listas", "Nivde017"));
        email.setSSLOnConnect(true);
        email.isStartTLSEnabled();
        email.setFrom("altabar.listas@gmail.com");
        email.setSubject(subject);
        email.setMsg(message);
        email.addTo("eacunagon@gmail.com");
        email.send();
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_INFO, "Listo!", "Lista enviada"));
    } catch (Exception ex) {
        FacesContext.getCurrentInstance().addMessage(null,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", ex.getMessage()));
        eMail = "";
        nombre = "";
        message = "";

    }

}

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 {//from  ww  w.  ja  v a 2s .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.qwazr.connectors.EmailConnector.java

public void sendEmail(Email email) throws EmailException {
    email.setHostName(hostname);
    if (ssl != null)
        email.setSSLOnConnect(ssl);/*from   w  w  w .ja va 2  s  .c  o  m*/
    if (start_tls_enabled != null)
        email.setStartTLSEnabled(start_tls_enabled);
    if (start_tls_required != null)
        email.setStartTLSRequired(start_tls_required);
    if (port != null)
        email.setSmtpPort(port);
    if (username != null)
        email.setAuthentication(username, password);
    if (connection_timeout != null)
        email.setSocketConnectionTimeout(connection_timeout);
    if (timeout != null)
        email.setSocketTimeout(timeout);
    email.send();
}

From source file:br.com.recursive.biblioteca.servicos.EmailService.java

public void sendHtmlEmail(Pessoa pessoa) throws EmailException {

    Email email = new HtmlEmail();
    email.setAuthenticator(new DefaultAuthenticator("claupwd@gmail.com", "@claupwd2014"));
    email.setHostName("smtp.gmail.com");
    email.setFrom("claupwd@gmail.com");
    email.setSubject("SIB Online - Recuperao de Senha");
    email.setMsg(createMessage(pessoa));
    email.addTo(pessoa.getContato().getEmail());
    email.setSSL(true);//from w  w w .ja  va2  s .  c o m
    //Se true, exibe na saida todo o processo do envio do email
    email.setDebug(true);
    email.send();
}

From source file:com.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");
    String ssl = request.getParameter("ssl");

    int mailServerPort = 25;
    try {//from  www .  jav  a2s .c o m
        mailServerPort = Integer.parseInt(smtpPort);
    } catch (Exception e) {
        LOG.info("The smtp port value is not a number. We will use default port value is 25");
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(smtpHost);
        email.setSmtpPort(mailServerPort);
        email.setAuthenticator(new DefaultAuthenticator(smtpUserName, smtpPassword));
        if ("true".equals(tls)) {
            email.setStartTLSEnabled(true);
        } else {
            email.setStartTLSEnabled(false);
        }

        if ("true".equals(ssl)) {
            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.");
        LOG.warn("Can not login to SMTP", e);
    }
}

From source file:com.qwazr.library.email.EmailConnector.java

public void sendEmail(final Email email) throws EmailException {
    email.setHostName(hostname);
    if (ssl != null)
        email.setSSLOnConnect(ssl);//from   w ww  .  j av a  2s. c  o m
    if (start_tls_enabled != null)
        email.setStartTLSEnabled(start_tls_enabled);
    if (start_tls_required != null)
        email.setStartTLSRequired(start_tls_required);
    if (port != null)
        email.setSmtpPort(port);
    if (username != null)
        email.setAuthentication(username, password);
    if (connection_timeout != null)
        email.setSocketConnectionTimeout(connection_timeout);
    if (timeout != null)
        email.setSocketTimeout(timeout);
    email.send();
}

From source file:com.kylinolap.common.util.MailService.java

/**
 * //w  w  w . j  a v a  2  s.  c om
 * @param receivers
 * @param subject
 * @param content
 * @return true or false indicating whether the email was delivered successfully
 * @throws IOException
 */
public boolean sendMail(List<String> receivers, String subject, String content) throws IOException {

    if (!enabled) {
        logger.info("Email service is disabled; this mail will not be delivered: " + subject);
        logger.info("To enable mail service, set 'mail.enabled=true' in kylin.properties");
        return false;
    }

    Email email = new HtmlEmail();
    email.setHostName(host);
    if (username != null && username.trim().length() > 0) {
        email.setAuthentication(username, password);
    }

    //email.setDebug(true);
    try {
        for (String receiver : receivers) {
            email.addTo(receiver);
        }

        email.setFrom(sender);
        email.setSubject(subject);
        email.setCharset("UTF-8");
        ((HtmlEmail) email).setHtmlMsg(content);
        email.send();
        email.getMailSession();

    } catch (EmailException e) {
        logger.error(e.getLocalizedMessage(), e);
        return false;
    }

    return true;
}

From source file:com.projetIF4.controller.MailControleur.java

public void mail() throws EmailException {
    Email email = new SimpleEmail();
    email.setCharset("UTF-8");
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(465);//from  w w w. j ava  2 s . c o m
    email.setAuthenticator(new DefaultAuthenticator("fst.rnu.info@gmail.com", "adminFST123456789"));
    email.setSSLOnConnect(true);
    email.setFrom("fst.rnu.info@gmail.com", "Dpartement Informatique FST");
    email.setSubject(objet);
    email.setMsg(message);
    email.addTo(mailDestination);
    email.send();
}

From source file:com.github.frapontillo.pulse.email.EmailNotifier.java

/**
 * Send an email, using the provided parameters, notifying if the pipeline succeeded or errored.
 *
 * @param parameters The {@link EmailNotifierConfig} to use.
 * @param isSuccess  {@code true} to report a success, {@code false} to report an error.
 *///  w  w w  . jav a2  s  .c o m
private void sendEmail(EmailNotifierConfig parameters, boolean isSuccess) {
    if (parameters.getAddresses() == null || parameters.getAddresses().length == 0) {
        return;
    }
    try {
        Email email = new SimpleEmail();
        email.setHostName(parameters.getHost());
        email.setSmtpPort(parameters.getPort());
        email.setAuthenticator(new DefaultAuthenticator(parameters.getUsername(), parameters.getPassword()));
        email.setSSLOnConnect(parameters.getUseSsl());
        email.setFrom(parameters.getFrom());
        email.setSubject(parameters.getSubject());
        String body;
        if (isSuccess) {
            body = parameters.getBodySuccess();
        } else {
            body = parameters.getBodyError();
        }
        body = body.replace("{{NAME}}", getProcessInfo().getName());
        email.setMsg(body);
        email.addTo(parameters.getAddresses());
        email.send();
    } catch (EmailException e) {
        logger.error(e);
        e.printStackTrace();
    }
}

From source file:com.packtpub.e4.advanced.event.mailman.MailSender.java

@Override
public void handleEvent(Event event) {
    String topic = event.getTopic();
    if (topic.startsWith("smtp/")) {
        String importance = topic.substring("smtp/".length());
        String to = (String) event.getProperty("To");
        String from = (String) event.getProperty("From");
        String subject = (String) event.getProperty("Subject");
        String body = (String) event.getProperty("DATA");
        try {/*  ww w. j a v  a2  s.  c om*/
            Email email = new SimpleEmail();
            email.setDebug(false);
            email.setHostName(hostname);
            email.setSmtpPort(port);
            email.setFrom(from);
            email.addTo(to);
            email.setSubject(subject);
            email.setMsg(body);
            email.addHeader("Importance", importance);
            email.send();
            log(LogService.LOG_INFO, "Message sent successfully to " + to);
        } catch (EmailException e) {
            log(LogService.LOG_ERROR, "Error occurred" + e);
        }
    }
}