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

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

Introduction

In this page you can find the example usage for org.apache.commons.mail MultiPartEmail 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:emailworkshop.EmailWorkshop.java

public static void enviaEmailComAnexo(String mailFrom, String senhaFrom, String emailTo, String nomeTo)
        throws EmailException {
    // cria o anexo 1.
    EmailAttachment anexo1 = new EmailAttachment();
    anexo1.setPath("Certificado.pdf"); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt)
    anexo1.setDisposition(EmailAttachment.ATTACHMENT);
    anexo1.setDescription("anexo");
    anexo1.setName("Certificado.pdf");

    // configura o email
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName("smtp.gmail.com"); // o servidor SMTP para envio do e-mail
    email.addTo(emailTo, nomeTo); //destinatrio
    email.setFrom(mailFrom, "UFPR"); // remetente
    email.setSubject("Certificado II Workshop de Inovao"); // assunto do e-mail
    email.setMsg("Segue anexo o Certificado de participaao no II Workshop, Obrigado pela presena! \n "
            + emailTo); //conteudo do e-mail
    email.setAuthentication(mailFrom, senhaFrom);
    email.setSmtpPort(465);//from www  .  j  a  v  a 2 s  .c o m
    email.setSSL(true);
    email.setTLS(true);
    // adiciona arquivo(s) anexo(s)
    email.attach(anexo1);
    // envia o email
    email.send();
}

From source file:com.github.somi92.seecsk.util.email.EmailSender.java

public static void sendEmail(EmailContainer ec) throws RuntimeException {

    try {/*from  w w  w . ja v a2s  .  c om*/

        String user = Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL);
        String password = Config.vratiInstancu()
                .vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_EMAIL_PASSWORD);

        EmailAttachment ea = new EmailAttachment();
        ea.setPath(ec.getAttachmentPath());
        ea.setDisposition(EmailAttachment.ATTACHMENT);
        ea.setDescription("Primer ispravno popunjene uplatnice za ?lanarinu");
        ea.setName("uplatnica.pdf");

        MultiPartEmail mpe = new MultiPartEmail();
        mpe.setDebug(true);
        mpe.setAuthenticator(new DefaultAuthenticator(user, password));
        mpe.setHostName(
                Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_HOST));
        mpe.setSSLOnConnect(true);
        mpe.setStartTLSEnabled(true);
        mpe.setSslSmtpPort(
                Config.vratiInstancu().vratiVrednost(Constants.EmailServerConfigKeys.EMAIL_SERVER_PORT));
        mpe.setSubject(ec.getSubject());
        mpe.setFrom(ec.getFromEmail(),
                Config.vratiInstancu().vratiVrednost(Constants.OrgInfoConfigKeys.ORGANISATION_NAME));
        mpe.setMsg(ec.getMessage());

        mpe.addTo(ec.getToEmail());
        mpe.attach(ea);

        mpe.send();

    } catch (EmailException ex) {
        ex.printStackTrace();
        throw new RuntimeException("Sistem nije uspeo da poalje email. Pokuajte ponovo.");
    }
}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void SendEmailSephoraPassedJava(String from, String grupSephora, String subject, String filename)
        throws FileNotFoundException, IOException {

    try {//  ww  w.  j a  v  a  2s .  c o  m

        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath(filename);
        attachment.setDisposition(EmailAttachment.ATTACHMENT);

        attachment.setDescription("rezultat TC-uri");
        attachment.setName("rezultat TC-uri");

        MultiPartEmail email = new MultiPartEmail();

        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(465);

        email.setAuthenticator(new DefaultAuthenticator("anda.cristea@contentspeed.ro", "testtest"));
        email.setSSLOnConnect(true);

        email.addTo(grupSephora);

        //email.addBcc(grupSephora);
        email.setFrom(from, "Teste Automate");
        email.setSubject(subject);
        email.setMsg(subject);

        // add the attachment
        //email.attach(attachment);
        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(new File(filename)), writer);

        email.setContent(writer.toString(), "text/html");
        email.attach(attachment);

        email.send();
        writer.close();
    } catch (Exception ex) {
        System.out.println("eroare trimitere email-uri");
        ex.printStackTrace();

    }

}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void SendEmail(String from, String to1, String to2, String subject, String filename)
        throws FileNotFoundException, IOException {

    try {//  w ww  .  j  a  v  a2  s. c  om

        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath(filename);
        attachment.setDisposition(EmailAttachment.ATTACHMENT);

        attachment.setDescription("rezultat TC-uri");
        attachment.setName("rezultat TC-uri");

        MultiPartEmail email = new MultiPartEmail();

        email.setHostName("smtp.gmail.com");
        email.setSmtpPort(465);
        //email.setAuthenticator(new DefaultAuthenticator("test@contentspeed.ro", "andaanda"));
        email.setAuthenticator(new DefaultAuthenticator("anda.cristea@contentspeed.ro", "anda.cristea"));
        email.setSSLOnConnect(true);

        email.addBcc(to1);
        email.addBcc(to2);
        email.setFrom(from, "Teste Automate");
        email.setSubject(subject);
        email.setMsg(subject);

        // add the attachment
        //email.attach(attachment);
        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(new File(filename)), writer);

        email.setContent(writer.toString(), "text/html");
        email.attach(attachment);

        // send the email
        email.send();
        writer.close();
    } catch (Exception ex) {
        System.out.println("eroare trimitere email-uri");
        System.out.println(ex.getMessage());

    }

}

From source file:br.com.cobranca.util.Util.java

/**
 * Metodo que envia email/*from  ww  w  .  ja  v  a2  s  .  co m*/
 *
 * @param divida
 * @param boleto
 */
public static void enviarEmail(Divida divida, String boleto) {
    MultiPartEmail emailTemp = new MultiPartEmail();

    try {

        emailTemp.setDebug(true);
        emailTemp.setHostName("smtp.gmail.com");
        emailTemp.setSmtpPort(587);
        emailTemp.setStartTLSEnabled(true);
        emailTemp.setAuthentication("homework.fca@gmail.com", "homework@");
        emailTemp.setFrom("syscob@sycob.com.br", "SYSCOB");
        emailTemp.addTo(divida.getDevedor().getEmail());
        emailTemp.setSubject("Boleto - Syscob ");
        emailTemp.setMsg("Ol, " + divida.getDevedor().getNome() + "\n"
                + "Segue anexo Boleto referente a negociao de cdigo: " + divida.getId() + "\n\n"
                + "Obs: Favor confirmar o recebimento deste. \n\n\n\n" + "Att \n" + "Syscob");

        boleto = boleto.replace("/", File.separator);

        File f = new File(boleto);
        EmailAttachment attachment = new EmailAttachment();
        attachment.setPath(f.getPath());
        attachment.setDisposition(EmailAttachment.ATTACHMENT);
        attachment.setName(f.getName());
        emailTemp.attach(attachment);

        emailTemp.send();

    } catch (Exception e) {
        System.out.println("Erro: " + e.getMessage());
    } finally {

    }

}

From source file:eu.ggnet.dwoss.mandator.api.value.Mandator.java

/**
 * Prepares a eMail to be send direct over the mandator smtp configuration.
 * The email is missing: to, subject, message and optional attachments.
 *
 * @return the email/*from   www  .  j a va2 s  .  com*/
 * @throws EmailException if something is wrong in the subsystem.
 */
public MultiPartEmail prepareDirectMail() throws EmailException {
    MultiPartEmail email = new MultiPartEmail();
    email.setHostName(smtpConfiguration.getHostname());
    email.addBcc(company.getEmail());
    email.setFrom(company.getEmail(), company.getEmailName());
    email.setAuthentication(smtpConfiguration.getSmtpAuthenticationUser(),
            smtpConfiguration.getSmtpAuthenticationPass());
    email.setStartTLSEnabled(false);
    email.setSSLCheckServerIdentity(false);
    email.setSSLOnConnect(false);
    email.setCharset(smtpConfiguration.getCharset());
    return email;
}

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

/**
 * envia email com arquivo anexo/* w w  w  . ja  v  a 2 s.c  o  m*/
 * @throws EmailException
 */
public void enviaEmailComAnexo(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem, List<String> anexos)
        throws EmailException, MalformedURLException {

    MultiPartEmail email = new MultiPartEmail();
    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);
    // adiciona arquivo(s) anexo(s)
    EmailAttachment anexo = new EmailAttachment();
    for (String arquivo : anexos) {
        anexo.setPath("/home/hslife/" + arquivo); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt)
        anexo.setDisposition(EmailAttachment.ATTACHMENT);
        anexo.setName(arquivo);
        email.attach(anexo);
        anexo = new EmailAttachment();
    }
    // Envia o e-mail
    email.send();
}

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

/**
 * envia email com arquivo anexo//ww w  .j  av  a2  s. c o m
 * @throws EmailException
 */
public void enviaEmailComAnexo(String nomeRementente, String emailRemetente, String nomeDestinatario,
        String emailDestinatario, String assunto, StringBuilder mensagem, List<String> anexos)
        throws EmailException, MalformedURLException {

    MultiPartEmail email = new MultiPartEmail();
    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.setCharset("UTF8");
    //email.setSmtpPort(465);
    //email.setSSL(true);
    //email.setTLS(true);
    // adiciona arquivo(s) anexo(s)
    EmailAttachment anexo = new EmailAttachment();
    for (String arquivo : anexos) {
        anexo.setPath("/home/hslife/" + arquivo); //caminho do arquivo (RAIZ_PROJETO/teste/teste.txt)
        anexo.setDisposition(EmailAttachment.ATTACHMENT);
        anexo.setName(arquivo);
        email.attach(anexo);
        anexo = new EmailAttachment();
    }
    // Envia o e-mail
    email.send();
}

From source file:com.dominion.salud.pedicom.negocio.tools.MAILTest.java

@Ignore
@Test/*from w  ww  .j a va 2  s . c om*/
public void send() {
    try {
        MultiPartEmail email = new MultiPartEmail();
        email.setHostName(SMTP);
        email.setAuthenticator(new DefaultAuthenticator(USUARIO, PASSWORD));
        email.setDebug(true);
        email.setSmtpPort(PUERTO);
        email.setStartTLSEnabled(true);

        email.setSSLOnConnect(true);

        email.setFrom(FROM, FROM);
        email.addTo(TO, TO);
        email.setSubject("Correo de Prueba");
        email.attach(new File("/home/jcgonzalez/TMP/a.hl7"));

        email.send();
    } catch (Exception e) {
        logger.error(e.toString());
    }
}

From source file:de.softwareforge.pgpsigner.commands.MailCommand.java

@Override
public void executeInteractiveCommand(final String[] args) {

    SecretKey secretKey = getContext().getSignKey();

    String senderMail = secretKey.getMailAddress();
    String senderName = secretKey.getName();

    if (StringUtils.isEmpty(senderMail)) {
        System.out.println("Could not extract sender mail from sign key.");
        return;//from  w  ww .ja v a 2s .  c om
    }

    for (final PublicKey key : getContext().getPartyRing().getVisibleKeys().values()) {

        if (key.isSigned() && !key.isMailed()) {

            try {
                String recipient = getContext().isSimulation() ? senderMail : key.getMailAddress();

                if (StringUtils.isEmpty(recipient)) {
                    System.out.println("No mail address for key " + key.getKeyId() + ", skipping.");
                    continue;
                }

                System.out.println("Sending Key " + key.getKeyId() + " to " + recipient);

                MultiPartEmail mail = new MultiPartEmail();
                mail.setHostName(getContext().getMailServerHost());
                mail.setSmtpPort(getContext().getMailServerPort());
                mail.setFrom(senderMail, senderName);
                mail.addTo(recipient);

                if (!getContext().isSimulation()) {
                    mail.addBcc(senderMail);
                }

                mail.setSubject("Your signed PGP key - " + key.getKeyId());
                mail.setMsg("This is your signed PGP key " + key.getKeyId() + " from the "
                        + getContext().getSignEvent() + " key signing event.");

                final String name = key.getKeyId() + ".asc";

                mail.attach(new DataSource() {

                    public String getContentType() {
                        return "application/pgp-keys";
                    }

                    public InputStream getInputStream() throws IOException {
                        return new ByteArrayInputStream(key.getArmor());
                    }

                    public String getName() {
                        return name;
                    }

                    public OutputStream getOutputStream() throws IOException {
                        throw new UnsupportedOperationException();
                    }
                }, name, "Signed Key " + key.getKeyId());

                mail.send();
                key.setMailed(true);

            } catch (EmailException ee) {
                System.out.println("Could not send mail for Key " + key.getKeyId());
            }
        }
    }
}