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

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

Introduction

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

Prototype

public Email setFrom(final String email, final String name) throws EmailException 

Source Link

Document

Set the FROM field of the email to use the specified address and the specified personal name.

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 {/*from   ww w.j a v a 2 s .  co 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: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  w w  . ja  v  a  2 s. co  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:dk.clarin.tools.workflow.java

public static void sendMail(int status, String name, String string1, String toolErrorMessage,
        String toolsandfiles, String mail2) throws org.apache.commons.mail.EmailException {
    try {//from ww w .  j  a va 2  s.c  o m
        logger.debug("sendMail(" + status + ", " + name + ", ... , ... , " + mail2 + ")");

        SimpleEmail email = new SimpleEmail();
        email.setHostName(ToolsProperties.mailServer);
        email.setFrom(ToolsProperties.mailFrom, ToolsProperties.mailFromName);
        email.setSmtpPort(Integer.parseInt(ToolsProperties.mailPort));
        email.setCharset("UTF-8");

        String body = "some body";
        String subject = "some subject ";
        switch (status) {
        case ACCEPT:
            subject = "[clarin.dk] Ny data fra integrerede vrktjer";
            body = "<html><body><p>"
                    + "Vi har modtaget dit nske om at oprette ny data ved hjlp af integrerede vrktjer.<br /><br />\n\n"
                    + "Nr oprettelsen er frdig, vil du modtage en email igen, der bekrfter at "
                    + "oprettelsen gik godt, samt en liste over URL'er hvor du vil kunne finde dine data<br /><br />\n\n"
                    + "Du kan ikke svare p denne email. Hvis ovenstende oplysninger ikke er rigtige, "
                    + "eller du har sprgsml, kan du henvende dig p mail-adressen admin@clarin.dk<br /><br />\n\n"
                    + "Venlig hilsen \nclarin.dk</p></body></html>";
            break;
        case WRAPUP:
            logger.debug("sendMail(" + status + ", " + name + ", " + string1 + ", " + toolErrorMessage + ", "
                    + toolsandfiles + ", " + mail2 + ")");
            subject = "[clarin.dk]  Samlet output fra integrerede vrktjer - success";
            body = "<html><body><p>"
                    + "Vi har modtaget dit nske om at oprette ny data ved hjlp af integrerede vrktjer.<br />\n\n"
                    + "Du kan se resultaterne her:<br /><br />\n\n";

            body += "<a href=\"" + string1 + "?JobNr=" + toolsandfiles + "\">resultater</a>";
            body += "\n\n<br /><br />Bemrk!<br />\n"
                    + "1) Hvert resultat kan hentes n gang, hvorefter resultatet straks slettes fra serveren.<br />\n"
                    + "2) Under alle omstndigheder slettes ikke-hentede resultaterne efter et par dage.<br /><br />\n\n"
                    + "Du kan ikke svare p denne email. Hvis ovenstende oplysninger ikke er rigtige, "
                    + "eller du har sprgsml, kan du henvende dig p mail-adressen admin@clarin.dk<br /><br />\n\n"
                    + "Venlig hilsen \nclarin.dk</p></body></html>";
            break;
        case ERRORUSER:
            subject = "[clarin.dk] Integreret vrktj melder fejl";
            body = "<html><body><p>" + string1 + (toolErrorMessage.equals("") ? ""
                    : "<br /><br />\n\nClarin.dk har modtaget denne besked fra vrktjet:<br /><br />\n\n"
                            + toolErrorMessage)
                    + "<br /><br />\n\n" + errorInfo(toolsandfiles)
                    + "<br /><br />\n\nDu kan ikke svare p denne email. Fejlbeskeden er ogs sendt til systemadministratoren."
                    + "<br /><br />\n\nVenlig hilsen\nclarin.dk</p></body></html>";
            break;
        default: //ERROR
            subject = "[clarin.dk] Integreret vrktj melder fejl";
            body = "<html><body><p>" + string1 + (toolErrorMessage.equals("") ? ""
                    : "<br /><br />\n\nClarin.dk har modtaget denne besked fra vrktjet:<br /><br />\n\n"
                            + toolErrorMessage)
                    + "<br /><br />\n\n" + errorInfo(toolsandfiles)
                    + "<br /><br />\n\nVenlig hilsen\nclarin.dk</p></body></html>";
            break;
        }
        email.setSubject(subject);
        email.setMsg(body);
        email.updateContentType("text/html; charset=UTF-8");
        email.addTo(mail2, name);
        email.send();
    } catch (org.apache.commons.mail.EmailException m) {
        logger.error("[Tools generated org.apache.commons.mail.EmailException] mailServer:"
                + ToolsProperties.mailServer + ", mailFrom:" + ToolsProperties.mailFrom + ", mailFromName:"
                + ToolsProperties.mailFromName + ", mailPort:" + Integer.parseInt(ToolsProperties.mailPort)
                + ", mail2:" + mail2 + ", name:" + name);
        //m.printStackTrace();
        logger.error("{} Error sending email. Message is: {}", "Tools", m.getMessage());
    } catch (Exception e) {//Catch exception if any
        logger.error("[Tools generated Exception] mailServer:" + ToolsProperties.mailServer + ", mailFrom:"
                + ToolsProperties.mailFrom + ", mailFromName:" + ToolsProperties.mailFromName + ", mailPort:"
                + Integer.parseInt(ToolsProperties.mailPort) + ", mail2:" + mail2 + ", name:" + name);
        logger.error("{} Exception:{}", "Tools", e.getMessage());
    }
}

From source file:funcoes.funcoes.java

public static void enviardEmailSimpes(String emailPara, String nomePara, String assunto, String mensagem)
        throws EmailException {

    SimpleEmail email = new SimpleEmail();
    //Utilize o hostname do seu provedor de email
    //System.out.println("alterando hostname...");

    email.setHostName("smtp.gmail.com");
    //Quando a porta utilizada no  a padro (gmail = 465)
    email.setSmtpPort(465);// w  w w.j  a  va2  s  .co  m
    //Adicione os destinatrios
    email.addTo(emailPara, nomePara);
    //Configure o seu email do qual enviar
    email.setFrom("cbjsolutions@gmail.com", "CBJ Solutions");
    //Adicione um assunto
    email.setSubject(assunto);
    //Adicione a mensagem do email
    email.setMsg(mensagem);
    //Para autenticar no servidor  necessrio chamar os dois mtodos abaixo
    //System.out.println("autenticando...");
    email.setSSL(true);
    email.setAuthentication("cbjsolutions", "slipclown");
    //System.out.println("enviando...");
    email.send();
    //System.out.println("Email enviado!");

}

From source file:de.knurt.fam.core.util.mail.UserMailSender.java

private static boolean send(UserMail um) {
    boolean sendSucc = false;
    UserMailSender dse = getInstance();//from  w  w  w.  j av a 2s  .co m
    if (um.hasBeenSent() == false) {
        if (um.mustBeSendNow()) {
            // prepare
            SimpleEmail email = new SimpleEmail();
            email.setHostName(dse.hostName);
            email.setSmtpPort(dse.smtpPort);
            // mail server using pass
            if (dse.authName != null) {
                email.setAuthentication(dse.authName, dse.authPass);
            }
            Map<String, String> headers = new Hashtable<String, String>();
            // headers.put("Subject", um.getSubject());
            email.setSubject(um.getSubject());
            headers.put("Content-Type", "text/plain; charset=utf-8");
            headers.put("Content-Transfer-Encoding", "base64");
            email.setHeaders(headers);
            boolean creatingSucc = false;
            try {
                email.addTo(um.getTo(), um.getUsername());
                email.setFrom(dse.fromMail, dse.fromName);
                email.setMsg(um.getMsg());
                creatingSucc = true;
            } catch (EmailException ex) {
                FamLog.logException(UserMailSender.class, ex,
                        "creating mail failed::" + um.getTo() + "::" + um.getUsername() + "::" + um.getId(),
                        200904031116l);
            }

            if (creatingSucc && FamConnector.isDev() == false) {
                try {
                    email.send();
                    sendSucc = true;
                } catch (EmailException ex) {
                    FamLog.exception("sending a mail failed: " + ex.getMessage() + "-" + dse.fromMail + "-"
                            + dse.fromName, ex, 200904031018l);
                }
            } else { // just dev mode - do not send any mails
                sendSucc = true;
            }
        }
    } else {
        FamLog.logException(UserMailSender.class,
                new DataIntegrityViolationException("try to send a mail twice"), "try to send a mail twice",
                200908201836l);
    }
    return sendSucc;
}

From source file:de.faustedition.EmailReporter.java

public void send(String subject, ReportCreator creator) throws EmailException {
    Preconditions.checkArgument(!Strings.isNullOrEmpty(subject));

    final StringWriter bodyWriter = new StringWriter();
    final PrintWriter bodyPrintWriter = new PrintWriter(bodyWriter);

    creator.create(bodyPrintWriter);/*from   w w  w  .  jav  a 2 s . c o m*/
    bodyPrintWriter.println();
    bodyPrintWriter.println("--");
    bodyPrintWriter.println("Digitale Faust-Edition");
    bodyPrintWriter.println("http://www.faustedition.net/");

    final String body = bodyWriter.toString();
    if (!mailEnabled) {
        logger.warn(String.format("\n\nSubject: %s\n\n%s\n\n", subject, body));
        return;
    }

    final SimpleEmail email = new SimpleEmail();
    email.setHostName("localhost");
    email.setFrom("noreply@faustedition.net", "Digitale Faust-Edition");
    email.addTo("gregor@middell.net", "Gregor Middell");
    email.addTo("m.wissenbach@gmx.de", "Moritz Wissenbach");
    email.setSubject(subject);
    email.setMsg(body);
    email.send();
}

From source file:br.com.painel.util.EnviarEmail.java

/**
 * /*from w  ww  .java  2s. co m*/
 * @param destino coloque o e-mail que da pessoa que deseja enviar
 * @param nomeDestino o nome do destino
 * @param assunto o assunto do email
 * @param mensagem a mensagem do email
 * @throws EmailException 
 */
public void enviarEmail(String destino, String nomeDestino, String assunto, String mensagem)
        throws EmailException {

    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail
    email.addTo(destino, nomeDestino); //destinatrio
    email.setFrom("rafaelvulner@gmail.com", "Recuperao de senha"); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem); //conteudo do e-mail
    email.setAuthentication("rafaelvulner", "rafad18m01");
    email.setSmtpPort(465);
    email.setSSL(true);
    email.setTLS(true);
    email.send(); //envia o e-mail
}

From source file:br.com.hslife.imobiliaria.service.EmailService.java

/**
  * envia email simples (smente texto)//from   w ww . ja va 2 s  .  c  o  m
  * Nome remetente, e-mail remetente, nome destinatario, e-mail destinatario,
  * assunto, mensagem
  * @param nomeRemetente
  * @param nomeDestinatario
  * @param emailRemetente
  * @param emailDestinatario
  * @param assunto
  * @param mensagem
  * @throws EmailException
  */
public void enviaEmailSimples(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem) throws EmailException {

    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatrio
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("realimoveis@hslife.com.br", "real123");
    //email.setSmtpPort(465);
    //email.setSSL(true);
    //email.setTLS(true);
    email.send();
}

From source file:br.com.hslife.catu.service.EmailService.java

/**
  * envia email simples (smente texto)/*from  www  .  j  a v a  2s  .c o  m*/
  * Nome remetente, e-mail remetente, nome destinatario, e-mail destinatario,
  * assunto, mensagem
  * @param nomeRemetente
  * @param nomeDestinatario
  * @param emailRemetente
  * @param emailDestinatario
  * @param assunto
  * @param mensagem
  * @throws EmailException
  */
public void enviaEmailSimples(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem) throws EmailException {

    SimpleEmail email = new SimpleEmail();
    email.setHostName("smtp.hslife.com.br"); // o servidor SMTP para envio do e-mail
    email.addTo(emailDestinatario, nomeDestinatario); //destinatrio
    email.setFrom(emailRemetente, nomeRementente); // remetente
    email.setSubject(assunto); // assunto do e-mail
    email.setMsg(mensagem.toString()); //conteudo do e-mail
    email.setAuthentication("nao-responde@hslife.com.br", "n0r3ply1@3");
    email.setCharset("UTF8");
    email.setSmtpPort(465);
    email.setSSL(true);
    email.setTLS(true);
    email.send();
}

From source file:dk.clarin.tools.rest.register.java

public void sendMail(String name, String mail2, String ToolName) {
    try {/*w ww  .java2  s  .  c om*/
        logger.debug("sendMail(" + name + ", " + mail2 + ", " + ToolName + ")");

        SimpleEmail email = new SimpleEmail();
        email.setHostName(ToolsProperties.mailServer);
        email.setFrom(ToolsProperties.mailFrom, ToolsProperties.mailFromName);
        email.setSmtpPort(Integer.parseInt(ToolsProperties.mailPort));
        email.setCharset("UTF-8");

        String body = "some body";
        String subject = "some subject ";
        subject = "[clarin.dk] web service wrapper (PHP) for registered tool";
        body = BracMat.Eval("wrapper$(PHP." + ToolName + ")");
        email.setSubject(subject);
        email.setMsg(body);
        email.updateContentType("text/x-php; charset=UTF-8");
        email.addTo(mail2, name);
        email.send();
    } catch (org.apache.commons.mail.EmailException m) {
        logger.error("[Tools generated org.apache.commons.mail.EmailException] mailServer:"
                + ToolsProperties.mailServer + ", mailFrom:" + ToolsProperties.mailFrom + ", mailFromName:"
                + ToolsProperties.mailFromName + ", mailPort:" + Integer.parseInt(ToolsProperties.mailPort)
                + ", mail2:" + mail2 + ", name:" + name);
        //m.printStackTrace();
        logger.error("{} Error sending email. Message is: {}", "Tools", m.getMessage());
    } catch (Exception e) {//Catch exception if any
        logger.error("[Tools generated Exception] mailServer:" + ToolsProperties.mailServer + ", mailFrom:"
                + ToolsProperties.mailFrom + ", mailFromName:" + ToolsProperties.mailFromName + ", mailPort:"
                + Integer.parseInt(ToolsProperties.mailPort) + ", mail2:" + mail2 + ", name:" + name);
        logger.error("{} Exception:{}", "Tools", e.getMessage());
    }
}