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

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

Introduction

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

Prototype

public Email setFrom(final String email) throws EmailException 

Source Link

Document

Set the FROM field of the email to use the specified address.

Usage

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

private void enviar(Email em, ConfiguracaoSQL conf, String destinatario) throws EmailException {
    try {/*from w  ww .  j  a 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);/* w ww.  java  2 s .co  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 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);/*from  w w  w  . j  a v a2 s . com*/
    // 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);
    email.setSSL(ssl);
    email.setTLS(tls);
    email.send();
}

From source file:com.actionbazaar.email.EmailService.java

/**
 * Sends out an email/*from  ww  w  . j  a va2s  .  co m*/
 * @param message - message to be sent
 */
public void onMessage(Message message) {

    try {
        EmailRequest emailRequest = (EmailRequest) ((ObjectMessage) message).getObject();

        Query query = entityManager.createQuery("select e from Email e where e.action = ?1");
        query.setParameter(1, emailRequest.getAction());
        List results = query.getResultList();
        if (results.size() != 1) {
            logger.severe("A total of " + results.size() + " email templates were returned for action "
                    + emailRequest.getAction());
            return;
        }
        System.out.println("--> Sending email.");
        Email emailInfo = (Email) results.get(0);
        logger.info("Speaker Directory: " + attachmentDirectory);
        HtmlEmail email = new HtmlEmail();
        email.setMailSession(mailSession);
        email.setTextMsg("Hello World!");
        //  email.setSubject(template.getSubject());
        email.addTo("rcuprak@mac.com");
        email.setFrom("java@ctjava.org");
        //  email.send();

        /*       emailTemplate.process(emailRecipient.getReplacementTokens());
                for (Map.Entry<String,File> entry : emailTemplate.getCidMappings().entrySet()) {
                    email.embed(entry.getValue(),entry.getKey());
                }
                email.setHtmlMsg(emailTemplate.getPatchedEmail());
          */
    } catch (Throwable t) {
        t.printStackTrace();
        //context.setRollbackOnly();
    }
}

From source file:libs.BuildMail.java

private void sendMail(String address, String subject, String msg) {
    try {//from  ww w.j a v  a 2s.  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:ca.ualberta.physics.cssdp.auth.service.EmailServiceImpl.java

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

    try {/*from   w  ww .  j  a  va 2 s. c  om*/

        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:br.com.itfox.utils.SendHtmlFormatedEmail.java

public void sendingHtml(String orderDetails, String orderNumber, String toName, String toEmail) {
    try {//from w w w  . ja  v  a2 s  .  com
        // Create the email message
        HtmlEmail email = new HtmlEmail();
        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("belchiorpalma@gmail.com", "xp2002b5"));
        email.setSSLOnConnect(true);
        email.setTLS(true);
        email.setFrom("contato@itfox.com.br");
        //email.setSubject("TestMail");
        email.addTo(toEmail, toName);
        //email.setFrom("belchiorpalma@me.com", "Me");
        //email.setSubject("Test email with inline image");
        email.setSubject(MimeUtility.encodeText("Thank you for your order", "UTF-8", "B"));

        // embed the image and get the content id
        //URL url = new URL("http://boutiquecellars.com/img/white-wines.jpg");
        //String cid = email.embed(url, "BoutiqueCellars.com");

        // set the html message
        email.setHtmlMsg("Thank you for your order\n<br/><br/>" + "\n" + "We received your order #"
                + orderNumber + " and we are working on it now.\n<br/>"
                + "We will e-mail you an update as soon as your order is processed.\n<br/>" + "\n<br/>"
                + "Boutique Cellars team\n"
                + "\n<br/><br/><img src='http://boutiquecellars.com/img/logoemail.jpg'/> \n" +
                //orderDetails +
                "<br/><br/>BOUTIQUE CELLARS SUPPORTS THE RESPONSIBLE SERVICE OF ALCOHOL. NSW: UNDER THE LIQUOR\n<br/>"
                + "ACT 2007 IT IS AGAINST THE LAW TO SELL OR SUPPLY ALCOHOL TO, OR TO OBTAIN ALCOHOL ON\n<br/>"
                + "BEHALF OF, A PERSON UNDER THE AGE OF 18 YEARS. NSW PACKAGED LIQUOR LICENCE NUMBER\n<br/>"
                + "LIQP770016947. YOUR CONTRACT OF SALE IS WITH THE RELEVANT LICENSEE AT THE RELEVANT\n<br/>"
                + "PREMISES FROM WHICH YOU ORDER IS ACCEPTED AND FULFILLED. LIQUOR IS SOLD FROM OUR\n<br/>"
                + "PLATFORM ON BEHALF OF THE RELEVANT LICENSEE. ACCORDINGLY, YOUR OFFER TO PURCHASE IS\n<br/>"
                + "SUBJECT TO ACCEPTANCE OF YOUR OFFER BY THE HOLDER OF THE LIQUOR LICENCE, CERTIFICATION\n<br/>"
                + "AND EVIDENCE OF YOU BEING OVER 18 YEARS OF AGE, THE AVAILABILITY OF STOCK AND THE\n<br/>"
                + "LIQUOR WHICH IS THE SUBJECT MATTER OF YOUR OFFER BEING ASCERTAINED AND APPROPRIATED\n<br/>"
                + "AT THE ABOVE MENTIONED LICENSED PREMISES.<br/><br/>"
                + " Boutique Cellar Imports Pty Ltd | ABN 69 607 265 618");

        // set the alternative message
        email.setTextMsg(
                "Thank you for your order, We received your order #18765 and we are working on it now.\n"
                        + "We will e-mail you an update as soon as your order is processed.\n" + "\n"
                        + "Boutique Cellars team");

        // send the email
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    }
    /*} catch (MalformedURLException ex) {
     Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    }*/

}

From source file:com.enseval.ttss.util.MailNotif.java

public void emailGiroTolak(Giro gironya, String namaCustomer, String customerID) {

    String port = (Executions.getCurrent().getServerPort() == 80) ? ""
            : (":" + Executions.getCurrent().getServerPort());
    String url = Executions.getCurrent().getScheme() + "://" + Executions.getCurrent().getServerName() + port
            + Executions.getCurrent().getContextPath() + "/info_giro.zul";

    String msg = "<html>" + "<head>"
            + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
            + "<title>Untitled Document</title>" + "<style type=\"text/css\">" + "p {"
            + "font-family: \"Courier New\", Courier, monospace;" + "font-size: 12px;" + "}" + "</style>"
            + "</head>" + "<p>Yth, </p>"
            + "<p>Berikut kami informasikan customer/outlet baru ditambahkan dalam daftar giro tolak;</p> "
            + "<br/>" + "<p><pre>" + "Customer ID      : " + customerID + "<br/>" + "Nama Customer    : "
            + namaCustomer + "<br/>" + "Nomor Giro       : " + gironya.getNomorGiro() + "<br/>"
            + "Nilai            : " + Rupiah.format(gironya.getNilai()) + "<br/>" + "Bank             : "
            + gironya.getBank() + "<br/>" + "Keterangan       : " + gironya.getKeterangan() + "" + "<pre>"
            + "</p>" + "<br/>" + "<br/>" + "<br/>"
            + "<p>Outlet akan di hold sementara oleh bagian Data Proses, selama di hold outlet tidak bisa melakukan order</p>"
            + "<br/>" + "<br/>" + "<p><i>Note : " + "<br>" + "Info giro " + url + "<br/>"
            + "Ini adalah email otomatis, mohon tidak membalas email ini !</i></p>" + "</html>";

    try {//from  w w  w  . j a  v a2s.  c  o m
        HtmlEmail mail = new HtmlEmail();
        mail.setHostName(Util.setting("smtp_host"));
        mail.setSmtpPort(Integer.parseInt(Util.setting("smtp_port")));
        mail.setAuthenticator((Authenticator) new DefaultAuthenticator(Util.setting("smtp_username"),
                Util.setting("smtp_password")));
        mail.setFrom(Util.setting("email_from"));
        for (String s : Util.setting("email_to").split(",")) {
            mail.addTo(s.trim());
        }

        mail.setSubject("[INFO GIRO TOLAK] - Nomor Giro : " + gironya.getNomorGiro() + " , Customer : "
                + namaCustomer + " (" + customerID + ")");
        mail.setHtmlMsg(msg);
        mail.send();
    } catch (EmailException ex) {
        Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:com.enseval.ttss.util.MailNotif.java

public void emailTolakUpdate(Giro gironya) {

    String port = (Executions.getCurrent().getServerPort() == 80) ? ""
            : (":" + Executions.getCurrent().getServerPort());
    String url = Executions.getCurrent().getScheme() + "://" + Executions.getCurrent().getServerName() + port
            + Executions.getCurrent().getContextPath() + "/info_giro.zul";

    String msg = "<html>" + "<head>"
            + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />"
            + "<title>Untitled Document</title>" + "<style type=\"text/css\">" + "p {"
            + "font-family: \"Courier New\", Courier, monospace;" + "font-size: 12px;" + "}" + "</style>"
            + "</head>" + "<p>Yth, </p>"
            + "<p>Berikut kami informasikan giro tolakan berikut sudah di proses kliring ulang;</p> " + "<br/>"
            + "<p><pre>" + "Customer ID      : " + gironya.getCustomer().getId() + "<br/>"
            + "Nama Customer    : " + gironya.getCustomer().getNama() + "<br/>" + "Nomor Giro       : "
            + gironya.getNomorGiro() + "<br/>" + "Nilai            : " + Rupiah.format(gironya.getNilai())
            + "<br/>" + "Bank             : " + gironya.getBank() + "<br/>" + "Tgl Kliring      : "
            + gironya.getTglKliring() + "<br/>" + "Keterangan       : " + gironya.getKeterangan() + "" + "<pre>"
            + "</p>" + "<br/>" + "<br/>" + "<br/>"
            + "<p>Jika tidak ada tolakan, account shipto customer akan segera diaktifkan oleh bagian Data Proses.</p>"
            + "<br/>" + "<br/>" + "<p><i>Note : " + "<br>" + "Info giro " + url + "<br/>"
            + "Ini adalah email otomatis, mohon tidak membalas email ini !</i></p>" + "</html>";

    try {/*from  www . ja va  2s.c o m*/
        HtmlEmail mail = new HtmlEmail();
        mail.setHostName(Util.setting("smtp_host"));
        mail.setSmtpPort(Integer.parseInt(Util.setting("smtp_port")));
        mail.setAuthenticator((Authenticator) new DefaultAuthenticator(Util.setting("smtp_username"),
                Util.setting("smtp_password")));
        mail.setFrom(Util.setting("email_from"));
        for (String s : Util.setting("email_to").split(",")) {
            mail.addTo(s.trim());
        }

        mail.setSubject("[INFO GIRO TOLAK - Update] - Nomor Giro : " + gironya.getNomorGiro() + " , Customer : "
                + gironya.getCustomer().getNama() + " (" + gironya.getCustomer().getId() + ")");
        mail.setHtmlMsg(msg);
        mail.send();
    } catch (EmailException ex) {
        Logger.getLogger(Util.class.getName()).log(Level.SEVERE, null, ex);
    }

}

From source file:br.com.itfox.beans.SendHtmlFormatedEmail.java

public void sendingHtml() {
    try {/*from  ww  w  .  jav  a  2 s .  c o  m*/
        // Create the email message
        HtmlEmail email = new HtmlEmail();
        email.setHostName("mail.congressotrt15.com.br");
        email.setSmtpPort(587);
        email.setAuthenticator(new DefaultAuthenticator("congresso@congressotrt15.com.br", "admtrt15xx"));
        email.setSSLOnConnect(false);
        //email.setTLS(true);
        email.setFrom("congresso@congressotrt15.com.br");
        email.setSubject("TestMail");
        email.addTo("belchiorpalma@gmail.com", "Belchior Palma");
        //email.setFrom("belchiorpalma@me.com", "Me");
        email.setSubject("Test email with inline image");
        email.setSubject(MimeUtility.encodeText("Test email with inline image", "UTF-8", "B"));

        // embed the image and get the content id
        URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
        String cid = email.embed(url, "Apache logo");

        // set the html message
        email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");

        // set the alternative message
        email.setTextMsg("Your email client does not support HTML messages");

        // send the email
        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    } catch (UnsupportedEncodingException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    } catch (MalformedURLException ex) {
        Logger.getLogger(SendHtmlFormatedEmail.class.getName()).log(Level.SEVERE, null, ex);
    }

}