Example usage for org.apache.commons.mail SimpleEmail SimpleEmail

List of usage examples for org.apache.commons.mail SimpleEmail SimpleEmail

Introduction

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

Prototype

SimpleEmail

Source Link

Usage

From source file:com.mycompany.webtestegit.util.TesteMail.java

public static void main(String[] args) {
    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail 
    try {/*w w  w  . j a v a2 s .c  o  m*/
        email.addTo("cfs.bsi@gmail.com", "Christian"); //destinatrio 
        email.setFrom("programacao.micromap@gmail.com", "Micromap"); // remetente 
        email.setSubject("Titulo do e-mail"); // assunto do e-mail 
        email.setMsg("Teste de Email utilizando commons-email"); //conteudo do e-mail 
        email.setAuthentication("ORIGEM", "SENHA");
        email.setSSLCheckServerIdentity(true);
        email.send(); //envia o e-mail
    } catch (EmailException ex) {
        Logger.getLogger(TesteMail.class.getName()).log(Level.SEVERE, null, ex);
    }

    //EMAIL HTML
    //        HtmlEmail email = new HtmlEmail();
    //
    //        try {
    //            email.setHostName("smtp.gmail.com");
    //            email.addTo("cfs.bsi@gmail.com", "Cfs");
    //            email.setFrom("programacao.micromap@gmail.com", "Micromap"); 
    //            email.setSubject("Teste de e-mail em formato HTML");   
    //
    //
    //            // adiciona uma imagem ao corpo da mensagem e retorna seu id 
    //            URL url = new URL("http://www.apache.org/images/asf_logo_wide.gif");
    //            String cid = email.embed(url, "Apache logo");   
    //
    //            // configura a mensagem para o formato HTML 
    //            email.setHtmlMsg("<html>The apache logo - <img src=\"cid:" + cid + "\"></html>");   
    //
    //            // configure uma mensagem alternativa caso o servidor no suporte HTML 
    //            email.setTextMsg("Seu servidor de e-mail no suporta mensagem HTML");   
    //            email.setAuthentication("ORIGEM", "SENHA");
    //            
    //            // envia o e-mail 
    //            email.send();
    //        } catch (EmailException ex) {
    //            Logger.getLogger(TesteMail.class.getName()).log(Level.SEVERE, null, ex);
    //        } catch (MalformedURLException ex) {
    //            Logger.getLogger(TesteMail.class.getName()).log(Level.SEVERE, null, ex);
    //        }
}

From source file:jobs.Utils.java

public static void emailAdmin(String subject, String message) {

    SimpleEmail email = new SimpleEmail();
    try {/*from   w  w w. j av a 2  s . c  o m*/
        email.setFrom("super.cool.bot@gmail.com");
        String address = (String) play.Play.configuration.get("mail.admin");
        email.addTo(address);
        email.setSubject(subject);
        email.setMsg(message);
        Mail.send(email);
    } catch (EmailException e) {
        Logger.error(e.getLocalizedMessage());
    }
}

From source file:com.kamike.misc.MailUtils.java

public static void sendSystemMail(String email, String msg) {
    SimpleEmail mail = new SimpleEmail();
    if (SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL_SMTP) == null
            && SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL) == null
            && SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL_ACCOUNT) == null
            && SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL_PASSWORD) == null) {
        //???//  w  ww .j  a  va  2  s.c o  m
        return;
    }
    try {
        mail.setHostName(SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL_SMTP));
        mail.addTo(email, email);
        mail.setFrom(SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL), "?");
        mail.setAuthentication(SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL_ACCOUNT),
                SystemConfig.getInstance().getParameter(SystemParam.SYSTEM_EMAIL_PASSWORD));
        mail.setSubject("??");
        mail.setMsg(msg);
        String a = mail.send();
        System.out.println(a);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:model.Email.java

public static void sendConfirmation(String receiver, String token, PersonalAccount account)
        throws EmailException {

    SimpleEmail email = new SimpleEmail();
    String message = "Sua conta foi criada com sucesso, porm ainda est inativa.\n";
    message += "Nmero da conta: " + account.getNumber() + "\n";
    message += "Agncia: " + account.getAgency().getNumber() + "\n";
    message += "Token de autentificao: " + token + "\n";
    message += "Com este token voc  capaz de definir uma senha para sua conta para, ento, utiliz-la.\n";
    message += "\nCaso voc perca este token, entre novamente com as informaes para abrir conta,";
    message += " e um novo token ser gerado e reenviado  voc.";

    try {/*w ww  .  jav a  2 s.  c  om*/
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        email.setAuthenticator(new DefaultAuthenticator("totheworldgroup@gmail.com", "albrcalu"));
        email.setSSLOnConnect(true);
        email.setFrom("totheworldgroup@gmail.com");
        email.setSubject("Token de autentificao");
        email.setMsg(message);
        email.addTo(receiver);
        email.send();

    } catch (EmailException e) {
        System.out.println(e.getMessage());
    }

}

From source file:model.EmailJava.java

public static void enviarEmail(String userEmail) {
    try {//from  w ww  . j  ava2 s .  co  m
        Email email = new SimpleEmail();
        email.setHostName("smtp.googlemail.com");
        email.setSmtpPort(465);
        //email.setAuthenticator(new DefaultAuthenticator("username", "password"));
        email.setAuthentication("codbarzmgbr@gmail.com ", "streetworkout2014");
        email.setSSLOnConnect(true);

        email.setFrom("jpmuniz88@gmail.com");

        email.setSubject("CodbarZ");
        email.setMsg("Junte-se ao CodbarZ. \n" + "Atleta junte-se ao nosso time, \n"
                + "empreendedores junte-se para nos apoiar, \n"
                + "Associe essa ideia, um projeto de inovado e aberto a todos que desejar evoluir com CodbarZ");
        email.addTo(userEmail);
        email.send();

    } catch (EmailException ex) {
        Logger.getLogger(EmailJava.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:connection.EmailSending.java

public static void sendTextEmail(String subject, String content, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(MailInfor.HOST_NAME);
    email.setSmtpPort(465);/*  w ww .ja v a2s.c  o m*/
    email.setAuthenticator(new DefaultAuthenticator(MailInfor.EMAIL_SENDER, MailInfor.PASSWORD));
    email.setSSLOnConnect(true);

    try {
        email.setFrom(MailInfor.EMAIL_SENDER);
        email.setSubject(subject);
        email.setMsg(content);
        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {
        Logger.getLogger(EmailSending.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ar.com.pahema.utils.MailSender.java

public static void enviar(String destino, Paquete paquete) throws EmailException {
    try {//from   www .j  a v  a 2  s. c  o m
        Email mail = new SimpleEmail();
        //Configuracion necesaria para GMAIL
        mail.setHostName("mail.pahema.com.ar");
        //mail.setTLS(true);
        mail.setSmtpPort(25);
        //mail.setSSL(true);
        //En esta seccion colocar cuenta de usuario de Gmail y contrasea
        mail.setAuthentication("dante@pahema.com.ar", "Fuerza2015");

        //Cuenta de Email Destino
        // AC? IRIA LA DE ADMINISTRACION DE PAHEMA. mail.addTo("dante.gs@hotmail.com");
        mail.addTo(destino);
        //Cuenta de Email Origen, la misma con la que nos autenticamos
        mail.setFrom("dante@pahema.com.ar", "Pahema - Sistema Tango");
        //Titulo del Email
        mail.setSubject("Aviso de finalizacin de paquete de horas.");
        //Contenido del Email
        mail.setMsg("Estimado cliente,\n" + "Le informamos que su paquete de "
                + (int) paquete.getCantidadHoras() + " horas est por finalizar.\n" + "Le quedan por usar: "
                + (int) paquete.getHorasRestantes() + " horas.\n"
                + "Por favor comunquese con Pahema para el detalle de sus consumos: 4952 - 4789.\n"
                + "Muchas gracias.\n" + "Administracin.");
        mail.send();
    } catch (EmailException e) {
        System.out.println(e.getMessage());
        throw new RuntimeException("Ocurrio un error en el envio del mail");
    }
}

From source file:com.aprodher.actions.util.EmailUtils.java

public static Email conectaEmail() throws EmailException {
    Email email = new SimpleEmail();
    email.setHostName(HOSTNAME);//w  w  w . j av  a2s . c om
    email.setSmtpPort(587);
    email.setAuthenticator(new DefaultAuthenticator(USERNAME, PASSWORD));
    email.setSSL(true);
    email.setTLS(true);
    email.setFrom(EMAILORIGEM);
    return email;
}

From source file:controller.SendMailMachine.java

public static void sendMail(Cart cart, String recipientEmail) {
    Email email = new SimpleEmail();

    email.setHostName(HOST_NAME);/*from   ww w .  ja v a  2  s.  co  m*/
    email.setSmtpPort(465);
    email.setAuthenticator(new DefaultAuthenticator(EMAIL_SENDER, PASSWORD));
    email.setSSLOnConnect(true);

    String subject = "Thng tin ha n";
    String content = "\t\t\tTRUNG TM MUA SM BITTORRENT\n\nChi tit n hng ca bn: \n";
    for (Map.Entry<Integer, Item> entrySet : cart.getCartItem().entrySet()) {
        Item item = entrySet.getValue();
        content += item.getWatch().getName() + "\t\t\t\t\t\t" + item.getQuantity() + " x "
                + ((int) item.getWatch().getPrice()) + "000 VND\n";
    }
    content += "Tng ha n: " + ((int) cart.sumPrice()) + "000 VND";
    try {
        email.setFrom(EMAIL_SENDER);
        email.setCharset("UTF-8");
        email.setSubject(subject);
        email.setMsg(content);

        email.addTo(recipientEmail);

        email.send();
    } catch (EmailException ex) {

        ex.printStackTrace();
    }
}

From source file:com.reizes.shiva.net.mail.EmailSender.java

public static String sendMail(String host, int port, String from, String to, String subject, String text)
        throws IOException, EmailException {

    if (to != null && host != null) {
        String[] emailTo = StringUtils.split(to, ';');

        Email email = new SimpleEmail();
        email.setHostName(host);//  w w w  . j a va2 s  . c  o m
        email.setSmtpPort(port);
        email.setFrom(from);

        for (String recv : emailTo) {
            email.addTo(recv);
        }

        email.setSubject(subject);
        email.setMsg(text);
        return email.send();
    }

    return null;
}