Example usage for org.apache.commons.mail HtmlEmail setSubject

List of usage examples for org.apache.commons.mail HtmlEmail setSubject

Introduction

In this page you can find the example usage for org.apache.commons.mail HtmlEmail setSubject.

Prototype

public Email setSubject(final String aSubject) 

Source Link

Document

Set the email subject.

Usage

From source file:actors.ValidationEmailSender.java

@Override
public void onReceive(Object object) {
    if (!(object instanceof Email)) {
        return;//from   w  w w .  j a v a2  s  . com
    }

    Email email = (Email) object;

    final HtmlEmail htmlEmail = new HtmlEmail();

    try {
        htmlEmail.setFrom(Config.getEmailFromSmtp(), utils.Config.getSiteName());
        htmlEmail.addTo(email.email, email.user.name);
        htmlEmail.setSubject(Messages.get("emails.validation.email.title", utils.Config.getSiteName()));
        htmlEmail.setHtmlMsg(getMessage(email.confirmUrl));
        htmlEmail.setCharset("utf-8");
        Mailer.send(htmlEmail);
        String escapedTitle = htmlEmail.getSubject().replace("\"", "\\\"");
        String logEntry = String.format("\"%s\" %s", escapedTitle, htmlEmail.getToAddresses());
        play.Logger.of("mail").info(logEntry);
    } catch (Exception e) {
        Logger.warn("Failed to send a notification: " + email + "\n" + ExceptionUtils.getStackTrace(e));
    }
}

From source file:br.vn.Model.Filtros.Email.java

public void enviarHatml(String emailcliente) throws MalformedURLException {

    try {//  w w  w.j  a v a 2s  .  c  o  m
        // Criar a mensagem de e-mail
        HtmlEmail email = new HtmlEmail();
        email.setHostName("org.apache.commons");

        email.addTo("jdoe@somewhere.org", "John Doe");
        email.setFrom("me@apache.org", "Me");
        email.setSubject("Test email with inline image");

        //incorporar a imagem e obter o ID de contedo
        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
        String cid = email.embed(url, "Apache logo");

        // definir a mensagem HTML
        email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");

        // definir a mensagem alternativa
        email.setTextMsg("Your email client does not support HTML messages");

        // enviar o e-mail
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(Email.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ca.ualberta.physics.cssdp.auth.service.EmailServiceImpl.java

public void sendEmail(String from, String to, String subject, String body) {

    try {/*from   ww  w.  j a  v  a2s . co  m*/

        String host = AuthServer.properties().getString("smtpHost");
        int port = AuthServer.properties().getInt("smtpPort");
        final String user = AuthServer.properties().getString("smtpUsername");
        final String password = AuthServer.properties().getString("smtpPassword");
        String systemEmail = AuthServer.properties().getString("systemEmailAddress");
        boolean useSSL = AuthServer.properties().getBoolean("smtpUseSSL");
        boolean debug = AuthServer.properties().getBoolean("smtpDebug");

        HtmlEmail msg = new HtmlEmail();
        msg.setHostName(host);
        msg.setAuthentication(user, password);
        msg.setSmtpPort(port);
        msg.setSSL(useSSL);
        msg.setDebug(debug);
        msg.setSubject("Password Reset Request");
        msg.addTo(to);
        msg.setFrom(systemEmail);
        msg.setHtmlMsg(body);
        msg.send();

    } catch (Exception e) {
        e.printStackTrace();
        throw Throwables.propagate(Throwables.getRootCause(e));
    } finally {
    }

}

From source file:com.dattack.jtoolbox.commons.email.HtmlEmailBuilder.java

/**
 * Builder method.// w  ww  .  j  a  v a2  s .  co  m
 *
 * @return the HtmlEmail
 * @throws EmailException
 *             if an error occurs while creating the email
 */
public HtmlEmail build() throws EmailException {

    if (hostname == null || hostname.isEmpty()) {
        throw new EmailException(String.format("Invalid SMTP server (hostname: '%s')", hostname));
    }

    if (from == null || from.isEmpty()) {
        throw new EmailException(String.format("Invalid email address (FROM: '%s'", from));
    }

    final HtmlEmail email = new HtmlEmail();
    email.setHostName(hostname);
    email.setFrom(from);
    email.setSubject(subject);

    if (message != null && !message.isEmpty()) {
        email.setMsg(message);
    }

    if (port > 0) {
        email.setSmtpPort(port);
    }

    if (username != null && !username.isEmpty()) {
        email.setAuthenticator(new DefaultAuthenticator(username, password));
    }

    if (sslOnConnect != null) {
        email.setSSLOnConnect(sslOnConnect);
    }

    if (startTlsEnabled != null) {
        email.setStartTLSEnabled(startTlsEnabled);
    }

    if (!toList.isEmpty()) {
        email.setTo(toList);
    }

    if (!ccList.isEmpty()) {
        email.setCc(ccList);
    }

    if (!bccList.isEmpty()) {
        email.setBcc(bccList);
    }
    return email;
}

From source file:com.fatecib.projetoemail.servlets.DAO.Enviaremail2.java

private void enviar(Email em, ConfiguracaoSQL conf, String destinatario) throws EmailException {
    try {/*from   ww  w.  ja va  2  s . c  om*/
        HtmlEmail email = new HtmlEmail();
        email.setHostName(conf.getEMAILHOST());
        email.setSmtpPort(conf.getPORTASMTP());
        email.setAuthenticator(new DefaultAuthenticator(conf.getUsuario(), conf.getSENHA()));
        email.setSSL(true);
        email.setFrom(conf.getUsuario());
        email.setSubject(em.getTitulo());
        email.setHtmlMsg(em.getConteudo());
        // set the alternative message
        email.setTextMsg("Email enviado com sucesso");
        email.addTo(destinatario);
        email.send();
    } catch (Exception e) {
        throw e;
    }

}

From source file:com.elexcode.emailservicelibrary.service.EmailSenderServiceImpl.java

@Override
public void sendEmail(EmailObject emailObject) throws Exception {
    HtmlEmail email = new HtmlEmail();
    email.setHostName(host);//  ww w. j a  va2s  .c  o m
    email.setSmtpPort(port);
    email.setAuthentication(username, password);
    for (String recipient : emailObject.getRecipients()) {
        email.addTo(recipient);
    }
    email.setFrom(username);
    email.setSubject(emailObject.getSubject());
    if (checkStringNotNullNotEmpty(emailObject.getHtmlMsg())) {
        email.setHtmlMsg(emailObject.getHtmlMsg());
    } else {
        if (checkStringNotNullNotEmpty(emailObject.getMessage())) {
            email.setTextMsg(emailObject.getMessage());
        }
    }
    email.setDebug(false);
    email.setTLS(true);
    email.setSSL(true);
    email.send();
}

From source file:br.com.atmatech.sac.controller.Email.java

public void emailAtendimento(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls,
        String emailto, String emailfrom, String solicitante, String nchamado, String razao, String data,
        String solicitacao, String realizacao, String tecnico, String imagem)
        throws EmailException, MalformedURLException {
    System.err.println(smtp + ":\n" + user + ":\n" + password + ":\n" + porta + ":\n" + ssl + ":\n" + tls
            + ":\n" + emailto + ":\n" + emailfrom + ":\n" + solicitante + ":\n" + nchamado + ":\n" + razao
            + ":\n" + data + ":\n" + solicitacao + ":\n" + realizacao + ":\n" + tecnico + ":\n" + imagem);
    HtmlEmail email = new HtmlEmail();
    // SimpleEmail email = new SimpleEmail();
    email.setHostName(smtp); // o servidor SMTP para envio do e-mail
    email.addTo(emailto); //destinatrio
    email.setFrom(emailfrom); // remetente        
    email.setSubject("Aviso de Atendimento - Suporte");
    // configura a mensagem para o formato HTML        
    email.setHtmlMsg(//from  w ww.  j  a v  a  2s.  co m
            "<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">Prezado(a)Senhor(a).<br>"
                    + "<b>" + solicitante + "</b><p>" + "Informamos que o protocolo nmero&#013<b> " + nchamado
                    + "</b> foi finalizado por nossa Central de Suporte.<p>" + "Cliente<br>" + "" + razao
                    + "<p>" + "Data<br>" + "" + data + "<p>" + "Descrio do Problema<br>" + "" + solicitacao
                    + "<p>" + "Soluo<br>" + "" + realizacao + "<p>" + "Atendente<br>" + "" + tecnico + "<p>"
                    + "<b>Atenciosamente</b> Suporte Atmatech<p><p>" + imagem + " </html>");
    //email.setMsg("Teste");
    email.setAuthentication(user, password);
    email.setSmtpPort(porta);
    email.setSSL(ssl);
    email.setTLS(tls);
    email.send();
}

From source file:com.cerebro.gorgone.commons.SendConfEmail.java

public SendConfEmail(String address, String confCode) {

    logger.info("Invio della mail di conferma");
    // Leggo i parametri di invio
    Properties props = new Properties();
    InputStream config = VaadinServlet.getCurrent().getServletContext()
            .getResourceAsStream("/WEB-INF/config.properties");
    if (config != null) {
        try {//from   w ww  .java  2  s . c  o m
            logger.info("Carico il file .properties");
            props.load(config);
        } catch (Exception ex) {
            logger.error("Errore nel caricamento del file .properties: " + ex.getMessage());
        }
    }
    smtp_host = props.getProperty(ConfigProperties.SMTP_HOST);
    smtp_port = Integer.getInteger(props.getProperty(ConfigProperties.SMTP_PORT));
    smtp_user = props.getProperty(ConfigProperties.SMTP_USER);
    smtp_pwd = props.getProperty(ConfigProperties.SMTP_PWD);
    smtp_security = Boolean.parseBoolean(ConfigProperties.SMTP_SECURITY);
    // Creo la mail
    HtmlEmail email = new HtmlEmail();
    try {
        email.setHostName(smtp_host);
        email.setSmtpPort(smtp_port);
        email.setSSLOnConnect(smtp_security);
        email.setAuthentication(smtp_user, smtp_pwd);
        email.setFrom("gioco@gioco.com", "Gioco");
        email.setSubject("Conferma il tuo indirizzo email " + confCode);
        email.addTo(address);
        email.setMsg("Messaggio della mail");
        email.send();
        logger.info("Email inviata");
    } catch (EmailException ex) {
        logger.error("Errore nell'invio della mail");
        logger.error(ex.getMessage());
    }
}

From source file:libs.BuildMail.java

private void sendMail(String address, String subject, String msg) {
    try {/*  ww w  .j a va2s  .c o m*/
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.ufpa.br");
        email.setSmtpPort(25);
        email.setAuthenticator(new DefaultAuthenticator("david.lopes@icen.ufpa.br", "spiderteste"));
        //email.setSSLOnConnect(); TODO verficar a possiblidade de uso SMTP
        email.setFrom("david.lopes@icen.ufpa.br");
        email.setSubject(subject);
        email.addTo(address);
        email.setHtmlMsg(msg);
        email.send();

    } catch (EmailException error) {
        System.out.println("Email error: check your log file" + error.getMessage());
    }
}

From source file:br.com.atmatech.sac.controller.Email.java

public void emai(String smtp, String user, String password, Integer porta, Boolean ssl, Boolean tls,
        String emailto, String emailfrom, String conteudo, String assunto)
        throws EmailException, MalformedURLException {
    HtmlEmail email = new HtmlEmail();
    email.setHostName(smtp); // o servidor SMTP para envio do e-mail                  
    email.addTo(emailto);//destinatario            
    conteudo = conteudo.replaceAll("\n", "<p>");
    email.setFrom(emailfrom); // remetente        
    //email.addCc(emailfrom);
    email.setSubject(assunto);
    // configura a mensagem para o formato HTML        
    email.setHtmlMsg("<html><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">"
            + conteudo + "</html>");
    email.setAuthentication(user, password);
    email.setSmtpPort(porta);/*ww  w. j a v  a  2 s. c o m*/
    email.setSSL(ssl);
    email.setTLS(tls);
    email.send();
}